Skip to content
Snippets Groups Projects
Commit 13588e3a authored by Angie Byron's avatar Angie Byron
Browse files

Revert "Issue #2563843 by heddn, jhodgdon, mradcliffe, swentel: MapItem...

Revert "Issue #2563843 by heddn, jhodgdon, mradcliffe, swentel: MapItem FieldType isn't used, documented, or tested: remove it"

Turns out contrib was making wide use of this.

This reverts commit 18026477.
parent 00d4deb8
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?php
/**
* @file
* Contains \Drupal\Core\Field\Plugin\Field\FieldType\MapItem.
*/
namespace Drupal\Core\Field\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\TypedData\DataDefinition;
/**
* Defines the 'map' entity field type.
*
* @FieldType(
* id = "map",
* label = @Translation("Map"),
* description = @Translation("An entity field for storing a serialized array of values."),
* no_ui = TRUE
* )
*/
class MapItem extends FieldItemBase {
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
// The properties are dynamic and can not be defined statically.
return array();
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
'value' => array(
'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 = array();
if (!isset($values)) {
return;
}
if (!is_array($values)) {
if ($values instanceof MapItem) {
$values = $values->getValue();
}
else {
$values = unserialize($values);
}
}
$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] = array();
}
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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment