You are here

class MigrateDefaultFieldHandler in Migrate 7.2

A fallback field handler to do basic copying of field data.

Hierarchy

Expanded class hierarchy of MigrateDefaultFieldHandler

File

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

View source
class MigrateDefaultFieldHandler extends MigrateFieldHandler {
  public function __construct() {
  }

  /**
   * Implements MigrateFieldHandler::fields().
   *
   * @param $field_type
   * @param $field_instance
   *
   * @return array
   */
  public function fields($field_type, $field_instance) {
    $field_info = field_info_field($field_instance['field_name']);
    $fields = array();
    $first = TRUE;
    foreach ($field_info['columns'] as $column_name => $column_info) {

      // The first column is the primary value, which is mapped directly to
      // the field name - so, don't include it here among the subfields.
      if ($first) {
        $first = FALSE;
      }
      else {
        $fields[$column_name] = empty($column_info['description']) ? $column_name : $column_info['description'];
      }
    }
    return $fields;
  }

  /**
   * Implements MigrateFieldHandler::prepare().
   *
   * @param $entity
   * @param array $field_info
   * @param array $instance
   * @param array $values
   *
   * @return null
   */
  public function prepare($entity, array $field_info, array $instance, array $values) {
    $arguments = array();
    if (isset($values['arguments'])) {
      $arguments = array_filter($values['arguments']);
      unset($values['arguments']);
    }
    $language = $this
      ->getFieldLanguage($entity, $field_info, $arguments);

    // Get the name of the primary (first) column, which is mapped separately.
    reset($field_info['columns']);
    $primary_column = key($field_info['columns']);

    // Setup the standard Field API array for saving.
    $delta = 0;
    foreach ($values as $value) {

      // Handle multivalue arguments (especially for subfields).
      $delta_arguments = array();
      foreach ($arguments as $name => $argument) {
        if (is_array($argument) && array_key_exists($delta, $argument)) {
          $delta_arguments[$name] = $argument[$delta];
        }
        else {
          $delta_arguments[$name] = $argument;
        }
      }
      $return[$language][$delta] = array(
        $primary_column => $value,
      ) + array_intersect_key($delta_arguments, $field_info['columns']);
      $delta++;
    }
    return isset($return) ? $return : NULL;
  }

  /**
   * Overrides MigrateHandler::handlesType().
   *
   * @param string $type
   *
   * @return bool
   */
  public function handlesType($type) {

    // We claim to handle any type.
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateDefaultFieldHandler::fields public function Implements MigrateFieldHandler::fields().
MigrateDefaultFieldHandler::handlesType public function Overrides MigrateHandler::handlesType(). Overrides MigrateHandler::handlesType
MigrateDefaultFieldHandler::prepare public function Implements MigrateFieldHandler::prepare().
MigrateDefaultFieldHandler::__construct public function Overrides MigrateHandler::__construct
MigrateFieldHandler::getFieldLanguage function Determine the language of the field.
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::registerTypes protected function Register a list of types handled by this class