public function Target::save in Drupal 7 to 8/9 Module Upgrader 8
Saves the file in which a particular node appears.
Parameters
\Pharborist\Node|null $node: The node to save. This can be positioned anywhere in the syntax tree. If NULL, all open files will be saved.
Throws
\Drupal\drupalmoduleupgrader\IOException
Overrides TargetInterface::save
File
- src/
Target.php, line 219
Class
- Target
- Default implementation of TargetInterface.
Namespace
Drupal\drupalmoduleupgraderCode
public function save(Node $node = NULL) {
if ($node) {
$file = $this
->getFileOf($node);
if ($file) {
$doc = $node instanceof RootNode ? $node : $node
->parents()
->get(0);
$victory = file_put_contents($file, $doc
->getText());
if ($victory === FALSE) {
throw new IOException((new FormattableMarkup('Failed to save @file.', [
'@file' => $file,
]))
->__toString());
}
}
else {
throw new IOException('Cannot save a node that is not attached to an open document.');
}
}
else {
array_walk($this->documents, [
$this,
'save',
]);
}
}