annotate modules/contrib/migrate_plus/src/Plugin/migrate/process/DomProcessBase.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents
children
rev   line source
Chris@5 1 <?php
Chris@5 2
Chris@5 3 namespace Drupal\migrate_plus\Plugin\migrate\process;
Chris@5 4
Chris@5 5 use Drupal\migrate\MigrateSkipRowException;
Chris@5 6 use Drupal\migrate\ProcessPluginBase;
Chris@5 7
Chris@5 8 /**
Chris@5 9 * Base class for process plugins that work with \DOMDocument objects.
Chris@5 10 *
Chris@5 11 * Use Dom::import() to convert a string to a \DOMDocument object, then plugins
Chris@5 12 * derived from this class to manipulate the object, then Dom::export() to
Chris@5 13 * convert back to a string.
Chris@5 14 */
Chris@5 15 abstract class DomProcessBase extends ProcessPluginBase {
Chris@5 16
Chris@5 17 /**
Chris@5 18 * Document to use.
Chris@5 19 *
Chris@5 20 * @var \DOMDocument
Chris@5 21 */
Chris@5 22 protected $document;
Chris@5 23
Chris@5 24 /**
Chris@5 25 * Xpath query object.
Chris@5 26 *
Chris@5 27 * @var \DOMXPath
Chris@5 28 */
Chris@5 29 protected $xpath;
Chris@5 30
Chris@5 31 /**
Chris@5 32 * Initialize the class properties.
Chris@5 33 *
Chris@5 34 * @param mixed $value
Chris@5 35 * Process plugin value.
Chris@5 36 * @param string $destination_property
Chris@5 37 * The name of the destination being processed. Used to generate an error
Chris@5 38 * message.
Chris@5 39 *
Chris@5 40 * @throws \Drupal\migrate\MigrateSkipRowException
Chris@5 41 * If $value is not a \DOMDocument object.
Chris@5 42 */
Chris@5 43 protected function init($value, $destination_property) {
Chris@5 44 if (!($value instanceof \DOMDocument)) {
Chris@5 45 $message = sprintf(
Chris@5 46 'The %s plugin in the %s process pipeline requires a \DOMDocument object. You can use the dom plugin to convert a string to \DOMDocument.',
Chris@5 47 $this->getPluginId(),
Chris@5 48 $destination_property
Chris@5 49 );
Chris@5 50 throw new MigrateSkipRowException($message);
Chris@5 51 }
Chris@5 52 $this->document = $value;
Chris@5 53 $this->xpath = new \DOMXPath($this->document);
Chris@5 54 }
Chris@5 55
Chris@5 56 }