pathauto.inc 1.2 KB

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