abstract class ArrayElement

Defines a generic configuration element that contains multiple properties.

Hierarchy

Expanded class hierarchy of ArrayElement

1 file declares its use of ArrayElement
LocaleTypedConfig.php in drupal/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php
Contains \Drupal\locale\LocaleTypedConfig.

File

drupal/core/lib/Drupal/Core/Config/Schema/ArrayElement.php, line 19
Contains \Drupal\Core\Config\Schema\ArrayElement.

Namespace

Drupal\Core\Config\Schema
View source
abstract class ArrayElement extends Element implements IteratorAggregate, ArrayAccess, Countable {

  /**
   * Parsed elements.
   */
  protected $elements;

  /**
   * Gets an array of contained elements.
   *
   * @return array
   *   Array of \Drupal\Core\Config\Schema\ArrayElement objects.
   */
  protected function getElements() {
    if (!isset($this->elements)) {
      $this->elements = $this
        ->parse();
    }
    return $this->elements;
  }

  /**
   * Gets valid configuration data keys.
   *
   * @return array
   *   Array of valid configuration data keys.
   */
  protected function getAllKeys() {
    return is_array($this->value) ? array_keys($this->value) : array();
  }

  /**
   * Builds an array of contained elements.
   *
   * @return array
   *   Array of \Drupal\Core\Config\Schema\ArrayElement objects.
   */
  protected abstract function parse();

  /**
   * Implements TypedDataInterface::validate().
   */
  public function validate() {
    foreach ($this
      ->getElements() as $element) {
      if (!$element
        ->validate()) {
        return FALSE;
      }
    }
    return TRUE;
  }

  /**
   * Implements ArrayAccess::offsetExists().
   */
  public function offsetExists($offset) {
    return array_key_exists($offset, $this
      ->getElements());
  }

  /**
   * Implements ArrayAccess::offsetGet().
   */
  public function offsetGet($offset) {
    $elements = $this
      ->getElements();
    return $elements[$offset];
  }

  /**
   * Implements ArrayAccess::offsetSet().
   */
  public function offsetSet($offset, $value) {
    if ($value instanceof TypedDataInterface) {
      $value = $value
        ->getValue();
    }
    $this->value[$offset] = $value;
    unset($this->elements);
  }

  /**
   * Implements ArrayAccess::offsetUnset().
   */
  public function offsetUnset($offset) {
    unset($this->value[$offset]);
    unset($this->elements);
  }

  /**
   * Implements Countable::count().
   */
  public function count() {
    return count($this
      ->getElements());
  }

  /**
   * Implements IteratorAggregate::getIterator();
   */
  public function getIterator() {
    return new ArrayIterator($this
      ->getElements());
  }

}

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::parse abstract protected function Builds an array of contained elements. 2
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.
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