function OptionsHooks::hasValuesInUse

Same name and namespace in other branches
  1. 11.x core/modules/options/src/Hook/OptionsHooks.php \Drupal\options\Hook\OptionsHooks::hasValuesInUse()

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

Parameters

string $entity_type_id: The entity type ID.

string $field_name: The field name.

array $values: The values to check.

1 call to OptionsHooks::hasValuesInUse()
OptionsHooks::fieldStorageConfigUpdateForbid in core/modules/options/src/Hook/OptionsHooks.php
Implements hook_field_storage_config_update_forbid().

File

core/modules/options/src/Hook/OptionsHooks.php, line 81

Class

OptionsHooks
Hook implementations for options.

Namespace

Drupal\options\Hook

Code

protected function hasValuesInUse(string $entity_type_id, string $field_name, array $values) : bool {
  if (empty($values)) {
    return FALSE;
  }
  return (bool) \Drupal::entityQuery($entity_type_id)->accessCheck(FALSE)
    ->condition($field_name . '.value', $values, 'IN')
    ->count()
    ->range(0, 1)
    ->execute();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.