You are here

function _options_values_in_use in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/options/options.module \_options_values_in_use()

Checks if a list of values are being used in actual field values.

3 calls to _options_values_in_use()
hook_field_storage_config_update_forbid in core/modules/field/field.api.php
Forbid a field storage update from occurring.
ListItemBase::validateAllowedValues in core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php
#element_validate callback for options field allowed values.
options_field_storage_config_update_forbid in core/modules/options/options.module
Implements hook_field_storage_config_update_forbid().

File

core/modules/options/options.module, line 123
Defines selection, check box and radio button widgets for text and numeric fields.

Code

function _options_values_in_use($entity_type, $field_name, $values) {
  if ($values) {
    $factory = \Drupal::service('entity.query');
    $result = $factory
      ->get($entity_type)
      ->condition($field_name . '.value', $values, 'IN')
      ->count()
      ->accessCheck(FALSE)
      ->range(0, 1)
      ->execute();
    if ($result) {
      return TRUE;
    }
  }
  return FALSE;
}