function _options_values_in_use

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

2 calls to _options_values_in_use()
options_field_settings_form_validate_allowed_values in drupal/core/modules/options/options.module
Element validate callback; check that the entered values are valid.
options_field_update_forbid in drupal/core/modules/options/options.module
Implements hook_field_update_forbid().

File

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

Code

function _options_values_in_use($field, $values) {
  if ($values) {
    $field = field_info_field_by_id($field['uuid']);
    $factory = Drupal::service('entity.query');
    foreach ($field['bundles'] as $entity_type => $bundle) {
      $result = $factory
        ->get($entity_type)
        ->condition($field['field_name'] . '.value', $values)
        ->count()
        ->accessCheck(FALSE)
        ->range(0, 1)
        ->execute();
      if ($result) {
        return TRUE;
      }
    }
  }
  return FALSE;
}