class Mapping

Same name in this branch

Defines a mapping configuration element.

Wraps configuration data and metadata allowing access to configuration data using the ComplexDataInterface API. This object may contain any number and type of nested properties.

Hierarchy

Expanded class hierarchy of Mapping

3 string references to 'Mapping'
picture.schema.yml in drupal/core/modules/picture/config/schema/picture.schema.yml
drupal/core/modules/picture/config/schema/picture.schema.yml
system.data_types.schema.yml in drupal/core/modules/system/config/schema/system.data_types.schema.yml
drupal/core/modules/system/config/schema/system.data_types.schema.yml
system.data_types.schema.yml in drupal/core/modules/system/config/schema/system.data_types.schema.yml
drupal/core/modules/system/config/schema/system.data_types.schema.yml

File

drupal/core/lib/Drupal/Core/Config/Schema/Mapping.php, line 22
Contains \Drupal\Core\Config\Schema\Mapping.

Namespace

Drupal\Core\Config\Schema
View source
class Mapping extends ArrayElement implements ComplexDataInterface {

  /**
   * Overrides ArrayElement::parse()
   */
  protected function parse() {
    $elements = array();
    foreach ($this->definition['mapping'] as $key => $definition) {
      if (isset($this->value[$key])) {
        $elements[$key] = $this
          ->parseElement($key, $this->value[$key], $definition);
      }
    }
    return $elements;
  }

  /**
   * Implements Drupal\Core\TypedData\ComplexDataInterface::get().
   */
  public function get($property_name) {
    $elements = $this
      ->getElements();
    if (isset($elements[$property_name])) {
      return $elements[$property_name];
    }
    else {
      throw new InvalidArgumentException(format_string("The configuration property @key doesn't exist.", array(
        '@key' => $property_name,
      )));
    }
  }

  /**
   * Implements Drupal\Core\TypedData\ComplexDataInterface::set().
   */
  public function set($property_name, $value, $notify = TRUE) {

    // Notify the parent of any changes to be made.
    if ($notify && isset($this->parent)) {
      $this->parent
        ->onChange($this->name);
    }

    // Set the data into the configuration array but behave according to the
    // interface specification when we've got a null value.
    if (isset($value)) {
      $this->value[$property_name] = $value;
      return $this
        ->get($property_name);
    }
    else {

      // In these objects, when clearing the value, the property is gone.
      // As this needs to return a property, we get it before we delete it.
      $property = $this
        ->get($property_name);
      unset($this->value[$property_name]);
      $property
        ->setValue($value);
      return $property;
    }
  }

  /**
   * Implements Drupal\Core\TypedData\ComplexDataInterface::getProperties().
   */
  public function getProperties($include_computed = FALSE) {
    return $this
      ->getElements();
  }

  /**
   * Implements Drupal\Core\TypedData\ComplexDataInterface::getPropertyValues().
   */
  public function getPropertyValues() {
    return $this
      ->getValue();
  }

  /**
   * Implements Drupal\Core\TypedData\ComplexDataInterface::setPropertyValues().
   */
  public function setPropertyValues($values) {
    foreach ($values as $name => $value) {
      $this->value[$name] = $value;
    }
    return $this;
  }

  /**
   * Implements Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinition().
   */
  public function getPropertyDefinition($name) {
    if (isset($this->definition['mapping'][$name])) {
      return $this->definition['mapping'][$name];
    }
    else {
      return FALSE;
    }
  }

  /**
   * Implements Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions().
   */
  public function getPropertyDefinitions() {
    $list = array();
    foreach ($this
      ->getAllKeys() as $key) {
      $list[$key] = $this
        ->getPropertyDefinition($key);
    }
    return $list;
  }

  /**
   * Implements Drupal\Core\TypedData\ComplexDataInterface::isEmpty().
   */
  public function isEmpty() {
    return empty($this->value);
  }

  /**
   * Implements \Drupal\Core\TypedData\ComplexDataInterface::onChange().
   */
  public function onChange($property_name) {

    // Notify the parent of changes.
    if (isset($this->parent)) {
      $this->parent
        ->onChange($this->name);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ArrayElement::$elements protected property Parsed elements.
ArrayElement::count public function Implements Countable::count().
ArrayElement::getAllKeys protected function Gets valid configuration data keys.
ArrayElement::getElements protected function Gets an array of contained elements.
ArrayElement::getIterator public function Implements IteratorAggregate::getIterator();
ArrayElement::offsetExists public function Implements ArrayAccess::offsetExists().
ArrayElement::offsetGet public function Implements ArrayAccess::offsetGet().
ArrayElement::offsetSet public function Implements ArrayAccess::offsetSet().
ArrayElement::offsetUnset public function Implements ArrayAccess::offsetUnset().
ArrayElement::validate public function Implements TypedDataInterface::validate(). Overrides TypedData::validate
Element::$value protected property The configuration value.
Element::parseElement protected function Create typed config object.
Mapping::get public function Implements Drupal\Core\TypedData\ComplexDataInterface::get(). Overrides ComplexDataInterface::get
Mapping::getProperties public function Implements Drupal\Core\TypedData\ComplexDataInterface::getProperties(). Overrides ComplexDataInterface::getProperties
Mapping::getPropertyDefinition public function Implements Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinition(). Overrides ComplexDataInterface::getPropertyDefinition
Mapping::getPropertyDefinitions public function Implements Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). Overrides ComplexDataInterface::getPropertyDefinitions
Mapping::getPropertyValues public function Implements Drupal\Core\TypedData\ComplexDataInterface::getPropertyValues(). Overrides ComplexDataInterface::getPropertyValues
Mapping::isEmpty public function Implements Drupal\Core\TypedData\ComplexDataInterface::isEmpty(). Overrides ComplexDataInterface::isEmpty
Mapping::onChange public function Implements \Drupal\Core\TypedData\ComplexDataInterface::onChange(). Overrides ComplexDataInterface::onChange
Mapping::parse protected function Overrides ArrayElement::parse() Overrides ArrayElement::parse
Mapping::set public function Implements Drupal\Core\TypedData\ComplexDataInterface::set(). Overrides ComplexDataInterface::set
Mapping::setPropertyValues public function Implements Drupal\Core\TypedData\ComplexDataInterface::setPropertyValues(). Overrides ComplexDataInterface::setPropertyValues
TypedData::$definition protected property The data definition.
TypedData::$name protected property The property name.
TypedData::$parent protected property The parent typed data object.
TypedData::getConstraints public function Implements \Drupal\Core\TypedData\TypedDataInterface::getConstraints(). Overrides TypedDataInterface::getConstraints 2
TypedData::getDefinition public function Implements \Drupal\Core\TypedData\TypedDataInterface::getDefinition(). Overrides TypedDataInterface::getDefinition
TypedData::getName public function Implements \Drupal\Core\TypedData\TypedDataInterface::getName(). Overrides TypedDataInterface::getName
TypedData::getParent public function Implements \Drupal\Core\TypedData\TypedDataInterface::getParent(). Overrides TypedDataInterface::getParent
TypedData::getPropertyPath public function Implements \Drupal\Core\TypedData\TypedDataInterface::getPropertyPath(). Overrides TypedDataInterface::getPropertyPath
TypedData::getRoot public function Implements \Drupal\Core\TypedData\TypedDataInterface::getRoot(). Overrides TypedDataInterface::getRoot
TypedData::getString public function Implements \Drupal\Core\TypedData\TypedDataInterface::getString(). Overrides TypedDataInterface::getString 7
TypedData::getType public function Implements \Drupal\Core\TypedData\TypedDataInterface::getType(). Overrides TypedDataInterface::getType
TypedData::getValue public function Implements \Drupal\Core\TypedData\TypedDataInterface::getValue(). Overrides TypedDataInterface::getValue 8
TypedData::setContext public function Implements \Drupal\Core\TypedData\TypedDataInterface::setContext(). Overrides TypedDataInterface::setContext 1
TypedData::setValue public function Implements \Drupal\Core\TypedData\TypedDataInterface::setValue(). Overrides TypedDataInterface::setValue 10
TypedData::__construct public function Constructs a TypedData object given its definition and context. 5