options.module
Same filename and directory in other branches
File
-
core/
modules/ options/ options.module
View source
<?php
/**
* @file
*/
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\options\OptionsAllowedValuesInterface;
/**
* Returns the array of allowed values for a list field.
*
* The strings are not safe for output. Keys and values of the array should be
* sanitized through \Drupal\Core\Field\FieldFilteredMarkup before being
* displayed.
*
* @param \Drupal\Core\Field\FieldStorageDefinitionInterface $definition
* The field storage definition.
* @param \Drupal\Core\Entity\FieldableEntityInterface|null $entity
* (optional) The specific entity when this function is called from the
* context of a specific field on a specific entity. This allows custom
* 'allowed_values_function' callbacks to either restrict the values or
* customize the labels for particular bundles and entities. NULL when
* there is not a specific entity available, such as for Views filters.
*
* @return array
* The array of allowed values. Keys of the array are the raw stored values
* (number or text), values of the array are the display labels.
*
* @deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use
* \Drupal\options\OptionsAllowedValuesInterface::allowedValues() instead.
*
* @see https://www.drupal.org/node/3572185
*/
function options_allowed_values(FieldStorageDefinitionInterface $definition, ?FieldableEntityInterface $entity = NULL) {
@trigger_error(__METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use \\Drupal\\options\\OptionsAllowedValuesInterface::allowedValues() instead. See https://www.drupal.org/node/3572185', E_USER_DEPRECATED);
return \Drupal::service(OptionsAllowedValuesInterface::class)->getAllowedValues($definition, $entity);
}
/**
* Checks if a list of values are being used in actual field values.
*
* @deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. The logic
* has been moved into \Drupal\options\Hook\OptionsHooks::hasValuesInUse()
* protected method and no replacement is provided.
*
* @see https://www.drupal.org/node/3572185
*/
function _options_values_in_use($entity_type, $field_name, $values) {
@trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. The logic has been moved into \\Drupal\\options\\Hook\\OptionsHooks::hasValuesInUse() protected method and no replacement is provided. See https://www.drupal.org/node/3572185', E_USER_DEPRECATED);
if ($values) {
$result = \Drupal::entityQuery($entity_type)->condition($field_name . '.value', $values, 'IN')
->count()
->accessCheck(FALSE)
->range(0, 1)
->execute();
if ($result) {
return TRUE;
}
}
return FALSE;
}
Functions
| Title | Deprecated | Summary |
|---|---|---|
| options_allowed_values | in drupal:11.5.0 and is removed from drupal:13.0.0. Use \Drupal\options\OptionsAllowedValuesInterface::allowedValues() instead. |
Returns the array of allowed values for a list field. |
| _options_values_in_use | in drupal:11.5.0 and is removed from drupal:13.0.0. The logic has been moved into \Drupal\options\Hook\OptionsHooks::hasValuesInUse() protected method and no replacement is provided. |
Checks if a list of values are being used in actual field values. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.