class MigrateDefaultFieldHandler in Migrate 7.2
A fallback field handler to do basic copying of field data.
Hierarchy
- class \MigrateHandler
- class \MigrateFieldHandler
- class \MigrateDefaultFieldHandler
- class \MigrateFieldHandler
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateDefaultFieldHandler:: |
public | function | Implements MigrateFieldHandler::fields(). | |
MigrateDefaultFieldHandler:: |
public | function |
Overrides MigrateHandler::handlesType(). Overrides MigrateHandler:: |
|
MigrateDefaultFieldHandler:: |
public | function | Implements MigrateFieldHandler::prepare(). | |
MigrateDefaultFieldHandler:: |
public | function |
Overrides MigrateHandler:: |
|
MigrateFieldHandler:: |
function | Determine the language of the field. | ||
MigrateHandler:: |
protected | property | List of other handler classes which should be invoked before the current one. | |
MigrateHandler:: |
protected | property | List of "types" handled by this handler. Depending on the kind of handler, these may be destination types, field types, etc. | |
MigrateHandler:: |
public | function | ||
MigrateHandler:: |
public | function | ||
MigrateHandler:: |
protected | function | Register a list of types handled by this class |