TermParent.php 988 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Drupal\reinstall\Plugin\migrate\process;
  3. use Drupal\migrate\MigrateExecutableInterface;
  4. use Drupal\migrate\ProcessPluginBase;
  5. use Drupal\migrate\Row;
  6. /**
  7. * Class TermParent works in conjunction with ReinstallTermSource.
  8. *
  9. * With the latter using the heavy-handed SimpleSource::flattenRow() method,
  10. * the parents obtained when migrating hierarchical vocabularies can be wrong,
  11. * especially with terms having multiple parents (i.e. non-tree graphs), and
  12. * this method allows the migration to obtain proper parent target_id values.
  13. *
  14. * @MigrateProcessPlugin(
  15. * id = "reinstall_term_parents"
  16. * )
  17. */
  18. class TermParent extends ProcessPluginBase {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function transform(
  23. $value,
  24. MigrateExecutableInterface $migrate_executable,
  25. Row $row,
  26. $destination_property
  27. ) {
  28. if (is_scalar($value)) {
  29. return $value;
  30. }
  31. elseif (isset($value['target_id'])) {
  32. return $value['target_id'];
  33. }
  34. }
  35. }