You are here

public function MigrateFieldsEntityHandler::fields in Migrate 7.2

Implementation of MigrateDestinationHandler::fields().

File

plugins/destinations/fields.inc, line 17
Support for processing entity fields

Class

MigrateFieldsEntityHandler
@file Support for processing entity fields

Code

public function fields($entity_type, $bundle, $migration = NULL) {
  $fields = array();
  $field_instance_info = field_info_instances($entity_type, $bundle);
  foreach ($field_instance_info as $machine_name => $instance) {
    $field_info = field_info_field($machine_name);
    $type = $field_info['type'];
    if (user_access(MIGRATE_ACCESS_ADVANCED)) {
      $fields[$machine_name] = $instance['label'] . ' (' . $field_info['type'] . ')';
    }
    else {
      $fields[$machine_name] = $instance['label'];
    }

    // Look for subfields.
    $class_list = _migrate_class_list('MigrateFieldHandler');
    $disabled = unserialize(variable_get('migrate_disabled_handlers', serialize(array())));
    $fields_found = FALSE;
    foreach ($class_list as $class_name => $handler) {
      if (!in_array($class_name, $disabled) && $handler
        ->handlesType($type) && method_exists($handler, 'fields')) {
        migrate_instrument_start($class_name . '->fields');
        $subfields = call_user_func(array(
          $handler,
          'fields',
        ), $type, $instance, $migration);
        migrate_instrument_stop($class_name . '->fields');
        foreach ($subfields as $subfield_name => $subfield_label) {
          $fields[$machine_name . ':' . $subfield_name] = $subfield_label;
        }
        $fields_found = TRUE;
      }
    }
    if (!$fields_found) {

      // Check the default field handler last.
      migrate_instrument_start('MigrateDefaultFieldHandler->fields');
      $subfields = call_user_func(array(
        new MigrateDefaultFieldHandler(),
        'fields',
      ), $type, $instance, $migration);
      migrate_instrument_stop('MigrateDefaultFieldHandler->fields');
      foreach ($subfields as $subfield_name => $subfield_label) {
        $fields[$machine_name . ':' . $subfield_name] = $subfield_label;
      }
    }
  }
  return $fields;
}