Sequence.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Drupal\Core\Config\Schema;
  3. /**
  4. * Defines a configuration element of type Sequence.
  5. *
  6. * This object may contain any number and type of nested elements that share
  7. * a common definition in the 'sequence' property of the configuration schema.
  8. *
  9. * Read https://www.drupal.org/node/1905070 for more details about configuration
  10. * schema, types and type resolution.
  11. *
  12. * Note that sequences implement the typed data ComplexDataInterface (via the
  13. * parent ArrayElement) rather than the ListInterface. This is because sequences
  14. * may have named keys, which is not supported by ListInterface. From the typed
  15. * data API perspective sequences are handled as ordered mappings without
  16. * metadata about existing properties.
  17. */
  18. class Sequence extends ArrayElement {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. protected function getElementDefinition($key) {
  23. $value = isset($this->value[$key]) ? $this->value[$key] : NULL;
  24. // @todo: Remove BC layer for sequence with hyphen in front. https://www.drupal.org/node/2444979
  25. $definition = [];
  26. if (isset($this->definition['sequence'][0])) {
  27. $definition = $this->definition['sequence'][0];
  28. }
  29. elseif ($this->definition['sequence']) {
  30. $definition = $this->definition['sequence'];
  31. }
  32. return $this->buildDataDefinition($definition, $value, $key);
  33. }
  34. }