class MapItem
Same name and namespace in other branches
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php \Drupal\Core\Field\Plugin\Field\FieldType\MapItem
- 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php \Drupal\Core\Field\Plugin\Field\FieldType\MapItem
- 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php \Drupal\Core\Field\Plugin\Field\FieldType\MapItem
Defines the 'map' entity field type.
Plugin annotation
@FieldType(
id = "map",
label = @Translation("Map"),
description = @Translation("An entity field for storing a serialized array of values."),
no_ui = TRUE,
list_class = "\Drupal\Core\Field\MapFieldItemList",
)
Hierarchy
- class \Drupal\Core\TypedData\TypedData implements \Drupal\Core\TypedData\TypedDataInterface, \Drupal\Component\Plugin\PluginInspectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\TypedData\TypedDataTrait
- class \Drupal\Core\TypedData\Plugin\DataType\Map extends \Drupal\Core\TypedData\TypedData implements \Drupal\Core\TypedData\Plugin\DataType\IteratorAggregate, \Drupal\Core\TypedData\ComplexDataInterface
- class \Drupal\Core\Field\FieldItemBase extends \Drupal\Core\TypedData\Plugin\DataType\Map implements \Drupal\Core\Field\FieldItemInterface
- class \Drupal\Core\Field\Plugin\Field\FieldType\MapItem extends \Drupal\Core\Field\FieldItemBase
- class \Drupal\Core\Field\FieldItemBase extends \Drupal\Core\TypedData\Plugin\DataType\Map implements \Drupal\Core\Field\FieldItemInterface
- class \Drupal\Core\TypedData\Plugin\DataType\Map extends \Drupal\Core\TypedData\TypedData implements \Drupal\Core\TypedData\Plugin\DataType\IteratorAggregate, \Drupal\Core\TypedData\ComplexDataInterface
Expanded class hierarchy of MapItem
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ MapItem.php, line 19
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeView source
class MapItem extends FieldItemBase {
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
// The properties are dynamic and can not be defined statically.
return [];
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'type' => 'blob',
'size' => 'big',
'serialize' => TRUE,
],
],
];
}
/**
* {@inheritdoc}
*/
public function toArray() {
// The default implementation of toArray() only returns known properties.
// For a map, return everything as the properties are not pre-defined.
return $this->getValue();
}
/**
* {@inheritdoc}
*/
public function setValue($values, $notify = TRUE) {
$this->values = [];
if (!isset($values)) {
return;
}
if (!is_array($values)) {
if ($values instanceof MapItem) {
$values = $values->getValue();
}
else {
$values = unserialize($values, [
'allowed_classes' => FALSE,
]);
}
}
$this->values = $values;
// Notify the parent of any changes.
if ($notify && isset($this->parent)) {
$this->parent
->onChange($this->name);
}
}
/**
* {@inheritdoc}
*/
public function __get($name) {
if (!isset($this->values[$name])) {
$this->values[$name] = [];
}
return $this->values[$name];
}
/**
* {@inheritdoc}
*/
public function __set($name, $value) {
if (isset($value)) {
$this->values[$name] = $value;
}
else {
unset($this->values[$name]);
}
}
/**
* {@inheritdoc}
*/
public static function mainPropertyName() {
// A map item has no main property.
return NULL;
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
return empty($this->values);
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.