class MigratePhysicalWeightFieldHandler in Physical Fields 7
Class MigratePhysicalWeightFieldHandler
Example: $this->addFieldMapping('field_weight', 'source_weight); $this->addFieldMapping('field_weight:unit') ->defaultValue('g');
Hierarchy
- class \MigrateHandler
- class \MigrateFieldHandler
Expanded class hierarchy of MigratePhysicalWeightFieldHandler
1 string reference to 'MigratePhysicalWeightFieldHandler'
- physical_migrate_api in ./
physical.migrate.inc - Implementation of hook_migrate_api().
File
- includes/
migrate/ weight.inc, line 11
View source
class MigratePhysicalWeightFieldHandler extends MigrateFieldHandler {
public function __construct() {
$this
->registerTypes(array(
'physical_weight',
));
}
static function arguments($unit = NULL) {
$arguments = array();
if (!is_null($unit)) {
$arguments['unit'] = $unit;
}
return $arguments;
}
/**
* Implementation of MigrateFieldHandler::fields().
*
* @param $type
* The field type.
* @param $instance
* Instance info for the field.
* @param Migration $migration
* The migration context for the parent field. We can look at the mappings
* and determine which subfields are relevant.
* @return array
*/
public function fields($type, $instance, $migration = NULL) {
return array(
'unit' => t('Subfield: The unit of measure for the weight'),
);
}
public function prepare($entity, array $field_info, array $instance, array $values) {
if (isset($values['arguments'])) {
$arguments = $values['arguments'];
unset($values['arguments']);
}
else {
$arguments = array();
}
$language = $this
->getFieldLanguage($entity, $field_info, $arguments);
foreach ($values as $delta => $value) {
$item = array();
if (isset($arguments['unit'])) {
if (!is_array($arguments['unit'])) {
$item['unit'] = $arguments['unit'];
}
else {
if (isset($arguments['unit'][$delta])) {
$item['unit'] = $arguments['unit'][$delta];
}
}
}
$item['weight'] = $value;
$return[$language][$delta] = $item;
}
return isset($return) ? $return : NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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:: |
public | function | Does this handler handle the given type? | 1 |
MigrateHandler:: |
protected | function | Register a list of types handled by this class | |
MigratePhysicalWeightFieldHandler:: |
static | function | ||
MigratePhysicalWeightFieldHandler:: |
public | function | Implementation of MigrateFieldHandler::fields(). | |
MigratePhysicalWeightFieldHandler:: |
public | function | ||
MigratePhysicalWeightFieldHandler:: |
public | function |
Overrides MigrateHandler:: |