diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index c9adb01..f2bd59f 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -362,7 +362,7 @@ public function getConstraints(DataDefinitionInterface $definition) { $class = $type_definition['class']; } // Check if the class provides allowed values. - if (is_subclass_of($class,'Drupal\Core\TypedData\AllowedValuesInterface') && is_subclass_of($class, 'Drupal\Core\TypedData\PrimitiveInterface')) { + if (is_subclass_of($class,'Drupal\Core\TypedData\AllowedValuesInterface')) { $constraints[] = $validation_manager->create('AllowedValues', array()); } diff --git a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php index d614277..bbcbc83 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php @@ -23,7 +23,7 @@ public function getPossibleValues(AccountInterface $account = NULL) { // Flatten options firstly, because Possible Options may contain group // arrays. - $flatten_options = $this->flattenOptions($this->getPossibleOptions($account)); + $flatten_options = \Drupal::formBuilder()->flattenOptions($this->getPossibleOptions($account)); return array_keys($flatten_options); } @@ -40,7 +40,7 @@ public function getPossibleOptions(AccountInterface $account = NULL) { public function getSettableValues(AccountInterface $account = NULL) { // Flatten options firstly, because Settable Options may contain group // arrays. - $flatten_options = $this->flattenOptions($this->getSettableOptions($account)); + $flatten_options = \Drupal::formBuilder()->flattenOptions($this->getSettableOptions($account)); return array_keys($flatten_options); } @@ -306,38 +306,4 @@ public function isEmpty() { return empty($value) && (string) $value !== '0'; } - /** - * {@inheritdoc} - */ - public function getConstraints() { - $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); - $constraints = parent::getConstraints(); - - $instance = $this->getFieldDefinition(); - $constraints[] = $constraint_manager->create('ComplexData', array( - 'value' => array( - 'AllowedValues' => array( - 'message' => t('%name: illegal value selected.', array('%name' => $instance->label)), - ), - ), - )); - - return $constraints; - } - - /** - * Flattens an array of allowed values. - * - * @param array $array - * A single or multidimensional array. - * - * @return array - * The flattened array. - */ - protected function flattenOptions(array $array) { - $result = array(); - array_walk_recursive($array, function($a, $b) use (&$result) { $result[$b] = $a; }); - return $result; - } - }