You are here

function _search_api_views_get_allowed_values in Search API 8

Retrieves the allowed values for a list field instance.

Parameters

string $entity_type: The entity type to which the field is attached.

string $bundle: The bundle to which the field is attached.

string $field_name: The field's field name.

Return value

array|null An array of allowed values in the form key => label, or NULL.

See also

_search_api_views_handler_adjustments()

1 string reference to '_search_api_views_get_allowed_values'
_search_api_views_handler_adjustments in ./search_api.views.inc
Makes necessary, field-specific adjustments to Views handler definitions.

File

./search_api.module, line 489
Provides a rich framework for creating searches.

Code

function _search_api_views_get_allowed_values($entity_type, $bundle, $field_name) {
  $field_manager = \Drupal::getContainer()
    ->get('entity_field.manager');
  $field_definitions = $field_manager
    ->getFieldDefinitions($entity_type, $bundle);
  if (!empty($field_definitions[$field_name])) {

    /** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
    $field_definition = $field_definitions[$field_name];
    $options = $field_definition
      ->getSetting('allowed_values');
    if ($options) {
      return $options;
    }
  }
  return NULL;
}