You are here

DomProcessBase.php in Migrate Plus 8.4

Same filename and directory in other branches
  1. 8.5 src/Plugin/migrate/process/DomProcessBase.php

File

src/Plugin/migrate/process/DomProcessBase.php
View source
<?php

namespace Drupal\migrate_plus\Plugin\migrate\process;

use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\ProcessPluginBase;

/**
 * Base class for process plugins that work with \DOMDocument objects.
 *
 * Use Dom::import() to convert a string to a \DOMDocument object, then plugins
 * derived from this class to manipulate the object, then Dom::export() to
 * convert back to a string.
 */
abstract class DomProcessBase extends ProcessPluginBase {

  /**
   * Document to use.
   *
   * @var \DOMDocument
   */
  protected $document;

  /**
   * Xpath query object.
   *
   * @var \DOMXPath
   */
  protected $xpath;

  /**
   * Initialize the class properties.
   *
   * @param mixed $value
   *   Process plugin value.
   * @param string $destination_property
   *   The name of the destination being processed. Used to generate an error
   *   message.
   *
   * @throws \Drupal\migrate\MigrateSkipRowException
   *   If $value is not a \DOMDocument object.
   */
  protected function init($value, $destination_property) {
    if (!$value instanceof \DOMDocument) {
      $message = sprintf('The %s plugin in the %s process pipeline requires a \\DOMDocument object. You can use the dom plugin to convert a string to \\DOMDocument.', $this
        ->getPluginId(), $destination_property);
      throw new MigrateSkipRowException($message);
    }
    $this->document = $value;
    $this->xpath = new \DOMXPath($this->document);
  }

}

Classes

Namesort descending Description
DomProcessBase Base class for process plugins that work with \DOMDocument objects.