You are here

class MigrateFieldsNodeHandler in Migrate 6.2

@file Support for processing CCK fields

Hierarchy

Expanded class hierarchy of MigrateFieldsNodeHandler

1 string reference to 'MigrateFieldsNodeHandler'
migrate_migrate_api in ./migrate.module

File

plugins/destinations/fields.inc, line 8
Support for processing CCK fields

View source
class MigrateFieldsNodeHandler extends MigrateDestinationHandler {
  public function __construct() {
    $this
      ->registerTypes(array(
      'node',
    ));
  }
  public function fields($entity_type, $bundle) {
    $fields = array();
    if (module_exists('content')) {
      $content_info = _content_type_info();
      foreach ($content_info['content types'][$bundle]['fields'] as $machine_name => $instance) {
        $fields[$machine_name] = t('Node:') . ' ' . $instance['widget']['label'] . ' (' . $instance['type'] . ')';

        // Look for subfields
        $class_list = _migrate_class_list('MigrateFieldHandler');
        $disabled = unserialize(variable_get('migrate_disabled_handlers', serialize(array())));
        foreach ($class_list as $class_name => $handler) {
          if (!in_array($class_name, $disabled) && $handler
            ->handlesType($instance['type']) && method_exists($handler, 'fields')) {
            migrate_instrument_start($class_name . '->fields');
            $subfields = call_user_func(array(
              $handler,
              'fields',
            ), $instance['type']);
            migrate_instrument_stop($class_name . '->fields');
            foreach ($subfields as $subfield_name => $subfield_label) {
              $fields[$machine_name . ':' . $subfield_name] = $subfield_label;
            }
          }
        }
      }
    }
    return $fields;
  }
  public function prepare($entity, stdClass $row) {
    migrate_instrument_start('MigrateDestinationEntity->prepareFields');

    // Look for Field API fields attached to this destination and handle appropriately
    $migration = Migration::currentMigration();
    $destination = $migration
      ->getDestination();
    $bundle = $destination
      ->getBundle();
    $info = content_types($bundle);
    $instances = $info['fields'];
    foreach ($instances as $machine_name => $instance) {
      if (property_exists($entity, $machine_name)) {

        // Normalize to an array
        if (!is_array($entity->{$machine_name})) {
          $entity->{$machine_name} = array(
            $entity->{$machine_name},
          );
        }
        $entity->{$machine_name} = migrate_field_handler_invoke_all($entity, $instance, $entity->{$machine_name});
      }
    }
    migrate_instrument_stop('MigrateDestinationEntity->prepareFields');
  }
  public function complete($entity, stdClass $row) {
    migrate_instrument_start('MigrateDestinationEntity->completeFields');

    // Look for Field API fields attached to this destination and handle appropriately
    $migration = Migration::currentMigration();
    $destination = $migration
      ->getDestination();
    $entity_type = $destination
      ->getEntityType();
    $bundle = $destination
      ->getBundle();
    $info = content_types($bundle);
    $instances = $info['fields'];
    foreach ($instances as $machine_name => $instance) {
      if (property_exists($entity, $machine_name)) {

        // Normalize to an array
        if (!is_array($entity->{$machine_name})) {
          $entity->{$machine_name} = array(
            $entity->{$machine_name},
          );
        }
        migrate_field_handler_invoke_all($entity, $instance, $entity->{$machine_name}, 'complete');
      }
    }
    migrate_instrument_stop('MigrateDestinationEntity->completeFields');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateFieldsNodeHandler::complete public function
MigrateFieldsNodeHandler::fields public function
MigrateFieldsNodeHandler::prepare public function
MigrateFieldsNodeHandler::__construct public function Overrides MigrateHandler::__construct
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?
MigrateHandler::registerTypes protected function Register a list of types handled by this class