Map.php in Zircon Profile 8.0
File
core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php
View source
<?php
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\TypedData\TypedData;
use Drupal\Core\TypedData\ComplexDataInterface;
class Map extends TypedData implements \IteratorAggregate, ComplexDataInterface {
protected $definition;
protected $values = array();
protected $properties = array();
public function getValue() {
foreach ($this->properties as $name => $property) {
$definition = $property
->getDataDefinition();
if (!$definition
->isComputed()) {
$value = $property
->getValue();
if (isset($this->values) || isset($value)) {
$this->values[$name] = $value;
}
}
}
return $this->values;
}
public function setValue($values, $notify = TRUE) {
if (isset($values) && !is_array($values)) {
throw new \InvalidArgumentException("Invalid values given. Values must be represented as an associative array.");
}
$this->values = $values;
foreach ($this->properties as $name => $property) {
$value = isset($values[$name]) ? $values[$name] : NULL;
$property
->setValue($value, FALSE);
unset($this->values[$name]);
}
if ($notify && isset($this->parent)) {
$this->parent
->onChange($this->name);
}
}
public function getString() {
$strings = array();
foreach ($this
->getProperties() as $property) {
$strings[] = $property
->getString();
}
return implode(', ', array_filter($strings, '\\Drupal\\Component\\Utility\\Unicode::strlen'));
}
public function get($property_name) {
if (!isset($this->properties[$property_name])) {
$value = NULL;
if (isset($this->values[$property_name])) {
$value = $this->values[$property_name];
}
$this->properties[$property_name] = $this
->getTypedDataManager()
->getPropertyInstance($this, $property_name, $value);
}
return $this->properties[$property_name];
}
public function set($property_name, $value, $notify = TRUE) {
$this
->writePropertyValue($property_name, $value);
$this
->onChange($property_name, $notify);
return $this;
}
protected function writePropertyValue($property_name, $value) {
if ($this->definition
->getPropertyDefinition($property_name)) {
$this
->get($property_name)
->setValue($value, FALSE);
}
else {
$this->values[$property_name] = $value;
}
}
public function getProperties($include_computed = FALSE) {
$properties = array();
foreach ($this->definition
->getPropertyDefinitions() as $name => $definition) {
if ($include_computed || !$definition
->isComputed()) {
$properties[$name] = $this
->get($name);
}
}
return $properties;
}
public function toArray() {
$values = array();
foreach ($this
->getProperties() as $name => $property) {
$values[$name] = $property
->getValue();
}
return $values;
}
public function getIterator() {
return new \ArrayIterator($this
->getProperties());
}
public function isEmpty() {
foreach ($this->properties as $property) {
$definition = $property
->getDataDefinition();
if (!$definition
->isComputed() && $property
->getValue() !== NULL) {
return FALSE;
}
}
if (isset($this->values)) {
foreach ($this->values as $name => $value) {
if (isset($value) && !isset($this->properties[$name])) {
return FALSE;
}
}
}
return TRUE;
}
public function __clone() {
foreach ($this->properties as $name => $property) {
$this->properties[$name] = clone $property;
$this->properties[$name]
->setContext($name, $this);
}
}
public function onChange($property_name, $notify = TRUE) {
if ($notify && isset($this->parent)) {
$this->parent
->onChange($this->name);
}
}
public function applyDefaultValue($notify = TRUE) {
foreach ($this
->getProperties() as $property) {
$property
->applyDefaultValue(FALSE);
}
return $this;
}
}
Classes
Name |
Description |
Map |
The "map" data type. |