diff --git a/core/lib/Drupal/Core/TypedData/AllowedValuesInterface.php b/core/lib/Drupal/Core/TypedData/AllowedValuesInterface.php index 2610e97..f340ba5 100644 --- a/core/lib/Drupal/Core/TypedData/AllowedValuesInterface.php +++ b/core/lib/Drupal/Core/TypedData/AllowedValuesInterface.php @@ -10,17 +10,17 @@ use Drupal\Core\Session\AccountInterface; /** - * Interface for retrieving allowed and possible values. + * Interface for retrieving all possible and settable values. * - * While possible values specify which values existing data might have, allowed + * While possible values specify which values existing data might have, settable * values define the values that are allowed to be set by a user. * - * For example, in an workflow scenario, the allowed values for a state field + * For example, in an workflow scenario, the settable values for a state field * might depend on the currently set state, while possible values are all - * states. Thus allowed values would be used in an editing context, while + * states. Thus settable values would be used in an editing context, while * possible values would be used for presenting filtering options in a search. * - * For convenience, lists of both allowed and possible values are also provided + * For convenience, lists of both settable and possible values are also provided * as structured options arrays that can be used in an Options widget such as a * select box or checkboxes. * @@ -29,56 +29,64 @@ interface AllowedValuesInterface { /** - * Returns an array of allowed values. + * Returns an array of all possible values. + * + * If the optional $account parameter is passed, then the array is filtered to + * values viewable by the account. * * @param \Drupal\Core\Session\AccountInterface $account - * (optional) The user account for which to generate the allowed values. + * (optional) The user account for which to filter the possible values. * * @return array - * An array of allowed values. + * An array of all possible values. */ - public function getValues(AccountInterface $account = NULL); + public function getAllPossibleValues(AccountInterface $account = NULL); /** - * Returns an array of allowed options. + * Returns an array of all possible values with labels for display. + * + * If the optional $account parameter is passed, then the array is filtered to + * values viewable by the account. * * @param \Drupal\Core\Session\AccountInterface $account - * (optional) The user account for which to generate the allowed options. + * (optional) The user account for which to filter the possible options. * * @return array - * The array of allowed options for the object; e.g. for display within a + * The array of possible options for the object; e.g. for display within a * widget. This is either a flat array of option labels keyed by values, or * a multi-dimensional array of option groups; i.e., an array of flat option * arrays, keyed by option group label. Labels should NOT be sanitized. - * - * @see Drupal\Core\TypedData\AllowedValuesInterface::getValues() */ - public function getOptions(AccountInterface $account = NULL); + public function getAllPossibleOptions(AccountInterface $account = NULL); /** - * Returns an array of possible values. + * Returns an array of settable values. + * + * If the optional $account parameter is passed, then the array is filtered to + * values settable by the account. * * @param \Drupal\Core\Session\AccountInterface $account - * (optional) The user account for which to generate the possible values. + * (optional) The user account for which to filter the settable values. * * @return array - * An array of possible values. + * An array of settable values. */ - public function getPossibleValues(AccountInterface $account = NULL); + public function getSettableValues(AccountInterface $account = NULL); /** - * Returns an array of possible options. + * Returns an array of settable values with lables for display. + * + * If the optional $account parameter is passed, then the array is filtered to + * values settable by the account. * * @param \Drupal\Core\Session\AccountInterface $account - * (optional) The user account for which to generate the possible options. + * (optional) The user account for which to filter the settable options. * * @return array - * The array of possible options for the object; e.g. for display within a + * The array of settable options for the object; e.g. for display within a * widget. This is either a flat array of option labels keyed by values, or * a multi-dimensional array of option groups; i.e., an array of flat option * arrays, keyed by option group label. Labels should NOT be sanitized. - * - * @see Drupal\Core\TypedData\AllowedValuesInterface::getOptions() */ - public function getPossibleOptions(AccountInterface $account = NULL); + public function getSettableOptions(AccountInterface $account = NULL); } diff --git a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/AllowedValuesConstraintValidator.php b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/AllowedValuesConstraintValidator.php index 8003fec..af2efb6 100644 --- a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/AllowedValuesConstraintValidator.php +++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/AllowedValuesConstraintValidator.php @@ -21,7 +21,7 @@ class AllowedValuesConstraintValidator extends ChoiceValidator { */ public function validate($value, Constraint $constraint) { if ($this->context->getMetadata()->getTypedData() instanceof AllowedValuesInterface) { - $allowed_values = $this->context->getMetadata()->getTypedData()->getValues(); + $allowed_values = $this->context->getMetadata()->getTypedData()->getAllPossibleValues(); $constraint->choices = $allowed_values; } return parent::validate($value, $constraint); diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php index 1af9d4e..3887f62 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php @@ -113,7 +113,7 @@ public function prepareCache() { * * @see \Drupal\Core\TypedData\AllowedValuesInterface */ - public function getOptions() { + public function getSettableOptions() { $definition = $this->getPluginDefinition(); $callback = "{$definition['module']}_options_list"; if (function_exists($callback)) { diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/DataType/FilterFormat.php b/core/modules/filter/lib/Drupal/filter/Plugin/DataType/FilterFormat.php index b7f721f..4d97b54 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/DataType/FilterFormat.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/DataType/FilterFormat.php @@ -26,14 +26,14 @@ class FilterFormat extends String implements AllowedValuesInterface { /** * {@inheritdoc} */ - public function getPossibleValues(AccountInterface $account = NULL) { - return array_keys($this->getPossibleOptions()); + public function getAllPossibleValues(AccountInterface $account = NULL) { + return array_keys($this->getAllPossibleOptions()); } /** * {@inheritdoc} */ - public function getPossibleOptions(AccountInterface $account = NULL) { + public function getAllPossibleOptions(AccountInterface $account = NULL) { $values = array(); foreach (filter_formats() as $format) { $values[$format->id()] = $format->label(); @@ -44,14 +44,14 @@ public function getPossibleOptions(AccountInterface $account = NULL) { /** * {@inheritdoc} */ - public function getValues(AccountInterface $account = NULL) { - return array_keys($this->getOptions($account)); + public function getSettableValues(AccountInterface $account = NULL) { + return array_keys($this->getSettableOptions($account)); } /** * {@inheritdoc} */ - public function getOptions(AccountInterface $user = NULL) { + public function getSettableOptions(AccountInterface $user = NULL) { $user = empty($user) ? $GLOBALS['user'] : $user; $values = array(); // @todo: Avoid calling functions but move to injected dependencies. diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php index afa0615..bf9d74a 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php @@ -204,18 +204,18 @@ function testTypedDataAPI() { // Test with anonymous user. $GLOBALS['user'] = drupal_anonymous_user(); - $available_values = $data->getPossibleValues(); + $available_values = $data->getAllPossibleValues(); $this->assertEqual($available_values, array('filtered_html', 'full_html', 'plain_text')); - $available_options = $data->getPossibleOptions(); + $available_options = $data->getAllPossibleOptions(); $expected_available_options = array( 'filtered_html' => 'Filtered HTML', 'full_html' => 'Full HTML', 'plain_text' => 'Plain text', ); $this->assertEqual($available_options, $expected_available_options); - $allowed_values = $data->getValues(); + $allowed_values = $data->getSettableValues(); $this->assertEqual($allowed_values, array('plain_text')); - $allowed_options = $data->getOptions(); + $allowed_options = $data->getSettableOptions(); $this->assertEqual($allowed_options, array('plain_text' => 'Plain text')); $data->setValue('foo'); @@ -242,9 +242,9 @@ function testTypedDataAPI() { $violations = $data->validate(); $this->assertEqual(count($violations), 0, "No validation violation for accessible format 'filtered_html' found."); - $allowed_values = $data->getValues(); + $allowed_values = $data->getSettableValues(); $this->assertEqual($allowed_values, array('filtered_html', 'plain_text')); - $allowed_options = $data->getOptions(); + $allowed_options = $data->getSettableOptions(); $expected_allowed_options = array( 'filtered_html' => 'Filtered HTML', 'plain_text' => 'Plain text',