diff --git a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php index 5dc9893..479c8cf 100644 --- a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php +++ b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php @@ -47,10 +47,20 @@ protected function parse() { } /** + * Gets data definition object for contained element. + * + * @param int|string $key + * Property name or index of the element. + * + * @return \Drupal\Core\TypedData\DataDefinitionInterface + */ + protected abstract function getElementDefinition($key); + + /** * {@inheritdoc} */ - public function get($property_name) { - $parts = explode('.', $property_name); + public function get($name) { + $parts = explode('.', $name); $root_key = array_shift($parts); $elements = $this->getElements(); if (isset($elements[$root_key])) { @@ -116,7 +126,7 @@ public function toArray() { /** * {@inheritdoc} */ - public function onChange($key) { + public function onChange($name) { // Notify the parent of changes. if (isset($this->parent)) { $this->parent->onChange($this->name); @@ -124,13 +134,6 @@ public function onChange($key) { } /** - * Implements Countable::count(). - */ - public function count() { - return count($this->getElements()); - } - - /** * Implements IteratorAggregate::getIterator(); */ public function getIterator() { diff --git a/core/lib/Drupal/Core/Config/Schema/Mapping.php b/core/lib/Drupal/Core/Config/Schema/Mapping.php index 82f4adc..5adfc20 100644 --- a/core/lib/Drupal/Core/Config/Schema/Mapping.php +++ b/core/lib/Drupal/Core/Config/Schema/Mapping.php @@ -28,7 +28,7 @@ class Mapping extends ArrayElement { /** * {@inheritdoc} */ - public function getElementDefinition($key) { + protected function getElementDefinition($key) { $value = isset($this->value[$key]) ? $this->value[$key] : NULL; $definition = isset($this->definition['mapping'][$key]) ? $this->definition['mapping'][$key] : array(); return $this->buildDataDefinition($definition, $value, $key); diff --git a/core/lib/Drupal/Core/Config/Schema/Sequence.php b/core/lib/Drupal/Core/Config/Schema/Sequence.php index 094f5e8..b7c34c2 100644 --- a/core/lib/Drupal/Core/Config/Schema/Sequence.php +++ b/core/lib/Drupal/Core/Config/Schema/Sequence.php @@ -21,7 +21,7 @@ class Sequence extends ArrayElement { /** * {@inheritdoc} */ - public function getElementDefinition($key) { + protected function getElementDefinition($key) { $value = isset($this->value[$key]) ? $this->value[$key] : NULL; $definition = isset($this->definition['sequence'][0]) ? $this->definition['sequence'][0] : array(); return $this->buildDataDefinition($definition, $value, $key); diff --git a/core/lib/Drupal/Core/Config/Schema/TypedConfigInterface.php b/core/lib/Drupal/Core/Config/Schema/TypedConfigInterface.php index 82120b8..8ce63df 100644 --- a/core/lib/Drupal/Core/Config/Schema/TypedConfigInterface.php +++ b/core/lib/Drupal/Core/Config/Schema/TypedConfigInterface.php @@ -20,17 +20,16 @@ * When implementing this interface which extends Traversable, make sure to list * IteratorAggregate or Iterator before this interface in the implements clause. */ -interface TypedConfigInterface extends TraversableTypedDataInterface, \Countable { +interface TypedConfigInterface extends TraversableTypedDataInterface { /** - * Determines whether the list contains any non-empty items. + * Determines whether the data structure is empty. * * @return boolean - * TRUE if the list is empty, FALSE otherwise. + * TRUE if the data structure is empty, FALSE otherwise. */ public function isEmpty(); - /** * Gets an array of contained elements. * @@ -39,21 +38,10 @@ public function isEmpty(); */ public function getElements(); - - /** - * Gets data definition object for contained element. - * - * @param int|string $key - * Property name or index of the element. - * - * @return \Drupal\Core\TypedData\DataDefinitionInterface - */ - public function getElementDefinition($key); - /** * Gets a contained typed configuration element. * - * @param $property_name + * @param $name * The name of the property to get; e.g., 'title' or 'name'. Nested * elements can be get using multiple dot delimited names, for example, * 'page.front'. @@ -64,7 +52,7 @@ public function getElementDefinition($key); * @return \Drupal\Core\TypedData\TypedDataInterface * The property object. */ - public function get($property_name); + public function get($name); /** * Replaces the item at the specified position in this list. @@ -87,13 +75,4 @@ public function set($key, $value); */ public function toArray(); - /** - * React to changes to a child element. - * - * Note that this is invoked after any changes have been applied. - * - * @param $key - * The key of the property which is changed. - */ - public function onChange($key); } diff --git a/core/modules/config/src/Tests/ConfigSchemaTest.php b/core/modules/config/src/Tests/ConfigSchemaTest.php index a23c90d..e8e04f4 100644 --- a/core/modules/config/src/Tests/ConfigSchemaTest.php +++ b/core/modules/config/src/Tests/ConfigSchemaTest.php @@ -292,12 +292,10 @@ function testSchemaData() { // Now let's try something more complex, with nested objects. $wrapper = \Drupal::service('config.typed')->get('image.style.large'); $effects = $wrapper->get('effects'); - - // The function is_array() doesn't work with ArrayAccess, so we use count(). - $this->assertTrue(count($effects) == 1, 'Got an array with effects for image.style.large data'); + $this->assertTrue(count($effects->toArray()) == 1, 'Got an array with effects for image.style.large data'); $uuid = key($effects->getValue()); $effect = $effects->get($uuid)->getElements(); - $this->assertTrue(count($effect['data']) && $effect['id']->getValue() == 'image_scale', 'Got data for the image scale effect from metadata.'); + $this->assertTrue(!$effect['data']->isEmpty() && $effect['id']->getValue() == 'image_scale', 'Got data for the image scale effect from metadata.'); $this->assertTrue($effect['data']->get('width') instanceof IntegerInterface, 'Got the right type for the scale effect width.'); $this->assertEqual($effect['data']->get('width')->getValue(), 480, 'Got the right value for the scale effect width.' );