class MigrateFieldsEntityHandler in Migrate 7.2
@file Support for processing entity fields
Hierarchy
- class \MigrateHandler
- class \MigrateDestinationHandler
- class \MigrateFieldsEntityHandler
- class \MigrateDestinationHandler
Expanded class hierarchy of MigrateFieldsEntityHandler
1 string reference to 'MigrateFieldsEntityHandler'
File
- plugins/
destinations/ fields.inc, line 8 - Support for processing entity fields
View source
class MigrateFieldsEntityHandler extends MigrateDestinationHandler {
public function __construct() {
$this
->registerTypes(array(
'entity',
));
}
/**
* Implementation of MigrateDestinationHandler::fields().
*/
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;
}
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();
$entity_type = $destination
->getEntityType();
$bundle = $destination
->getBundle();
$instances = field_info_instances($entity_type, $bundle);
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} = $entity->{$machine_name} ? array(
$entity->{$machine_name},
) : array();
}
$field_info = field_info_field($machine_name);
$entity->{$machine_name} = migrate_field_handler_invoke_all($entity, $field_info, $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();
$instances = field_info_instances($entity_type, $bundle);
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},
);
}
$field_info = field_info_field($machine_name);
migrate_field_handler_invoke_all($entity, $field_info, $instance, $entity->{$machine_name}, 'complete');
}
}
migrate_instrument_stop('MigrateDestinationEntity->completeFields');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateFieldsEntityHandler:: |
public | function | ||
MigrateFieldsEntityHandler:: |
public | function | Implementation of MigrateDestinationHandler::fields(). | |
MigrateFieldsEntityHandler:: |
public | function | ||
MigrateFieldsEntityHandler:: |
public | function |
Overrides MigrateHandler:: |
|
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:: |
public | function | Does this handler handle the given type? | 1 |
MigrateHandler:: |
protected | function | Register a list of types handled by this class |