dimensions.inc in Physical Fields 7
File
includes/migrate/dimensions.inc
View source
<?php
class MigratePhysicalDimensionsFieldHandler extends MigrateFieldHandler {
public function __construct() {
$this
->registerTypes(array(
'physical_dimensions',
));
}
static function arguments($unit = NULL) {
$arguments = array();
if (!is_null($unit)) {
$arguments['unit'] = $unit;
}
return $arguments;
}
public function fields($type, $instance, $migration = NULL) {
return array(
'length' => t('Subfield: !field', array(
'!field' => t('Length'),
)),
'width' => t('Subfield: !field', array(
'!field' => t('Width'),
)),
'height' => t('Subfield: !field', array(
'!field' => t('Height'),
)),
'unit' => t('Subfield: The unit of measure for the dimensions'),
);
}
public function prepare($entity, array $field_info, array $instance, array $values) {
if (isset($values['arguments'])) {
$arguments = $values['arguments'];
unset($values['arguments']);
}
else {
$arguments = array();
}
if (empty($values)) {
$values = array(
0 => '',
);
}
$language = $this
->getFieldLanguage($entity, $field_info, $arguments);
foreach ($values as $delta => $value) {
$item = array();
foreach (array_keys(self::fields('', '')) as $subfield) {
if (isset($arguments[$subfield])) {
if (!is_array($arguments[$subfield])) {
$item[$subfield] = $arguments[$subfield];
}
else {
if (isset($arguments[$subfield][$delta])) {
$item[$subfield] = $arguments[$subfield][$delta];
}
}
}
}
$return[$language][$delta] = $item;
}
return isset($return) ? $return : NULL;
}
}