abstract class MigrateSimpleFieldHandler in Migrate 6.2
Same name and namespace in other branches
- 7.2 plugins/destinations/fields.inc \MigrateSimpleFieldHandler
Base class for creating field handlers for fields with a single value.
To use this class just extend it and pass key where the field's value should be stored to the constructor, then register the type(s):
class MigrateLinkFieldHandler extends MigrateSimpleFieldHandler {
public function __construct() {
parent::__construct('url');
$this
->registerTypes(array(
'link',
));
}
}
Hierarchy
- class \MigrateHandler
- class \MigrateFieldHandler
- class \MigrateSimpleFieldHandler
- class \MigrateFieldHandler
Expanded class hierarchy of MigrateSimpleFieldHandler
File
- plugins/
destinations/ fields.inc, line 107 - Support for processing CCK fields
View source
abstract class MigrateSimpleFieldHandler extends MigrateFieldHandler {
protected $fieldValueKey = 'value';
protected $skipEmpty = FALSE;
/**
* Construct a simple field handler.
*
* @param $options
* Array of options (rather than unnamed parameters so you don't have to
* what TRUE or FALSE means). The following keys are used:
* - 'value_key' string with the name of the key in the fields value array.
* - 'skip_empty' Boolean indicating that empty values should not be saved.
*/
public function __construct($options = array()) {
if (isset($options['value_key'])) {
$this->fieldValueKey = $options['value_key'];
}
if (isset($options['skip_empty'])) {
$this->skipEmpty = $options['skip_empty'];
}
}
public function prepare($entity, array $instance, array $values) {
if (isset($values['arguments'])) {
unset($values['arguments']);
}
// Let the derived class skip empty values.
if ($this->skipEmpty) {
$values = array_filter($values, array(
$this,
'notNull',
));
}
// Setup the Field API array for saving.
$delta = 0;
foreach ($values as $value) {
$return[$delta][$this->fieldValueKey] = $value;
$delta++;
}
return isset($return) ? $return : NULL;
}
/**
* Returns TRUE only for values which are not NULL.
*
* @param $value
* @return bool
*/
protected function notNull($value) {
return !is_null($value);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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? | |
MigrateHandler:: |
protected | function | Register a list of types handled by this class | |
MigrateSimpleFieldHandler:: |
protected | property | ||
MigrateSimpleFieldHandler:: |
protected | property | ||
MigrateSimpleFieldHandler:: |
protected | function | Returns TRUE only for values which are not NULL. | |
MigrateSimpleFieldHandler:: |
public | function | ||
MigrateSimpleFieldHandler:: |
public | function |
Construct a simple field handler. Overrides MigrateHandler:: |
3 |