pathauto.migrate.inc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @file
  4. * Support for the Pathauto module.
  5. */
  6. /**
  7. * Field handler.
  8. */
  9. class PathautoMigrationHandler extends MigrateDestinationHandler {
  10. public function __construct() {
  11. $this->registerTypes(array('entity'));
  12. }
  13. /**
  14. * Make the destination field visible.
  15. */
  16. public function fields() {
  17. return array(
  18. 'pathauto' => t('Pathauto: Perform aliasing (set to 0 to prevent alias generation during migration'),
  19. );
  20. }
  21. public function prepare($entity, stdClass $row) {
  22. if (isset($entity->pathauto)) {
  23. if (!isset($entity->path)) {
  24. $entity->path = array();
  25. }
  26. elseif (is_string($entity->path)) {
  27. // If MigratePathEntityHandler->prepare() hasn't run yet, support
  28. // the alias (set as $entity->path as a string) being formatted properly
  29. // in the path alias array.
  30. $path = $entity->path;
  31. $entity->path = array();
  32. $entity->path['alias'] = $path;
  33. }
  34. $entity->path['pathauto'] = $entity->pathauto;
  35. if (!isset($entity->path['alias'])) {
  36. $entity->path['alias'] = '';
  37. }
  38. unset($entity->pathauto);
  39. }
  40. }
  41. }
  42. /*
  43. * Implementation of hook_migrate_api().
  44. */
  45. function pathauto_migrate_api() {
  46. $api = array(
  47. 'api' => 2,
  48. 'destination handlers' => array('PathautoMigrationHandler'),
  49. );
  50. return $api;
  51. }