ProcessPluginBase.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Drupal\migrate;
  3. use Drupal\Core\Plugin\PluginBase;
  4. use Drupal\migrate\Plugin\MigrateProcessInterface;
  5. /**
  6. * The base class for all migrate process plugins.
  7. *
  8. * Migrate process plugins are taking a value and transform them. For example,
  9. * transform a human provided name into a machine name, look up an identifier
  10. * in a previous migration and so on.
  11. *
  12. * @see https://www.drupal.org/node/2129651
  13. * @see \Drupal\migrate\Plugin\MigratePluginManager
  14. * @see \Drupal\migrate\Plugin\MigrateProcessInterface
  15. * @see \Drupal\migrate\Annotation\MigrateProcessPlugin
  16. * @see plugin_api
  17. *
  18. * @ingroup migration
  19. */
  20. abstract class ProcessPluginBase extends PluginBase implements MigrateProcessInterface {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  25. // Do not call this method from children.
  26. if (isset($this->configuration['method'])) {
  27. if (method_exists($this, $this->configuration['method'])) {
  28. return $this->{$this->configuration['method']}($value, $migrate_executable, $row, $destination_property);
  29. }
  30. throw new \BadMethodCallException(sprintf('The %s method does not exist in the %s plugin.', $this->configuration['method'], $this->pluginId));
  31. }
  32. else {
  33. throw new \BadMethodCallException(sprintf('The "method" key in the plugin configuration must to be set for the %s plugin.', $this->pluginId));
  34. }
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function multiple() {
  40. return FALSE;
  41. }
  42. }