public function Dom::import in Migrate Plus 8.4
Same name and namespace in other branches
- 8.5 src/Plugin/migrate/process/Dom.php \Drupal\migrate_plus\Plugin\migrate\process\Dom::import()
Converts a HTML string into a DOMDocument.
It is not using \Drupal\Component\Utility\Html::load() because it ignores all errors on import, and therefore incompatible with log_messages option.
Parameters
mixed $value: The string to be imported.
\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.
\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.
string $destination_property: The destination property currently worked on. This is only used together with the $row above.
Return value
\DOMDocument The document object based on the provided string.
Throws
\Drupal\migrate\MigrateException When the received $value is not a string.
File
- src/
Plugin/ migrate/ process/ Dom.php, line 147
Class
- Dom
- Handles string to DOM and back conversions.
Namespace
Drupal\migrate_plus\Plugin\migrate\processCode
public function import($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!is_string($value)) {
throw new MigrateException('Cannot import a non-string value.');
}
if ($this->logMessages) {
set_error_handler(function ($errno, $errstr) use ($migrate_executable) {
$migrate_executable
->saveMessage($errstr, MigrationInterface::MESSAGE_WARNING);
});
}
if ($this->nonRoot) {
$html = $this
->getNonRootHtml($value);
}
else {
$html = $value;
}
$document = new \DOMDocument($this->configuration['version'], $this->configuration['encoding']);
$document
->loadHTML($html);
if ($this->logMessages) {
restore_error_handler();
}
return $document;
}