You are here

class MigrateNodeHierarchyHandler in Node Hierarchy 7.4

Field handler.

Hierarchy

Expanded class hierarchy of MigrateNodeHierarchyHandler

1 string reference to 'MigrateNodeHierarchyHandler'
nodehierarchy_migrate_api in ./nodehierarchy.module
Implements hook_migrate_api().

File

./nodehierarchy.migrate.inc, line 11
Support for the Pathauto module.

View source
class MigrateNodeHierarchyHandler extends MigrateDestinationHandler {
  public function __construct() {
    $this
      ->registerTypes(array(
      'node',
    ));
  }

  /**
   * Make the destination field visible.
   */
  public function fields() {
    if (module_exists('nodehierarchy')) {
      return array(
        'nodehierarchy:pnid' => t('NodeHierarchy Parent: The node id of the parent node.'),
        'nodehierarchy:customized' => t('NodeHierarchy Customized: Whether the menu title is customized.'),
        'nodehierarchy:enabled' => t('NodeHierarchy Menu Enabled: Whether the menu is enabled.'),
        'nodehierarchy:description' => t('NodeHierarchy Menu Description: The menu description.'),
        'nodehierarchy:link_title' => t('NodeHierarchy Menu Title'),
        'nodehierarchy:expanded' => t('Is the NodeHierarchy menu expanded.'),
        'nodehierarchy:weight' => t('NodeHierarchy Menu Description: The menu description.'),
        'nodehierarchy:view' => t('NodeHierarchy View: The node embedded children view for this node.'),
      );
    }
    else {
      return array();
    }
  }
  public function prepare($entity, stdClass $row) {
    if (!empty($entity->nodehierarchy['arguments']['pnid']) || !empty($entity->nodehierarchy['arguments']['enabled'])) {

      // Load the existing menu items and defaults if any.
      nodehierarchy_node_prepare($entity);

      // Remove all but the primary parent.
      foreach ($entity->nodehierarchy_parents as $i => $parent) {

        // Keep the first one in case it has a menu which needs to be moved.
        if ($i !== 0) {
          $entity->nodehierarchy_parents[$i]->remove = TRUE;
        }
      }
      $entity->nodehierarchy_parents[0]->cnid = $entity->nid;
      $entity->nodehierarchy_parents[0]->pnid = $entity->nodehierarchy['arguments']['pnid'];
      $entity->nodehierarchy_parents[0]->cweight = $entity->nodehierarchy['arguments']['weight'];
      if (is_array($entity->nodehierarchy['arguments']['pnid'])) {
        $entity->nodehierarchy_parents[0]->pnid = array_shift($entity->nodehierarchy['arguments']['pnid']);
      }
      if (is_array($entity->nodehierarchy['arguments']['weight'])) {
        $entity->nodehierarchy_parents[0]->cweight = array_shift($entity->nodehierarchy['arguments']['weight']);
      }
      if (!empty($entity->nodehierarchy['arguments']['enabled'])) {
        foreach ($entity->nodehierarchy['arguments'] as $key => $val) {
          $entity->nodehierarchy_parents[0]->menu_link[$key] = $val;
        }
      }
    }

    // Add the embed view.
    if ($entity->nodehierarchy['arguments']['view']) {
      $entity->nh_children_view = $entity->nodehierarchy['arguments']['view'];
    }

    // Add any non-primary parents
    if (is_array($entity->nodehierarchy['arguments']['pnid'])) {
      foreach ($entity->nodehierarchy['arguments']['pnid'] as $i => $pnid) {
        $parent = _nodehierarchy_default_record($entity->nid, $entity->nodehierarchy['arguments']['pnid']);
        if (isset($entity->nodehierarchy['arguments']['pnid'][$i])) {
          $parent->cweight = $entity->nodehierarchy['arguments']['pnid'][$i];
        }
        $entity->nodehierarchy_parents[] = $parent;
      }
    }
    unset($entity->nodehierarchy);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateHandler::$dependencies protected property List of other handler classes which should be invoked before the current one.
MigrateHandler::$typesHandled protected property List of "types" handled by this handler. Depending on the kind of handler, these may be destination types, field types, etc.
MigrateHandler::getDependencies public function
MigrateHandler::getTypesHandled public function
MigrateHandler::handlesType public function Does this handler handle the given type? 1
MigrateHandler::registerTypes protected function Register a list of types handled by this class
MigrateNodeHierarchyHandler::fields public function Make the destination field visible.
MigrateNodeHierarchyHandler::prepare public function
MigrateNodeHierarchyHandler::__construct public function Overrides MigrateHandler::__construct