You are here

private function AllowedValuesConstraintValidator::getValidChoices in Select (or other) 8

Same name and namespace in other branches
  1. 4.x src/Plugin/Validation/AllowedValuesConstraintValidator.php \Drupal\select_or_other\Plugin\Validation\AllowedValuesConstraintValidator::getValidChoices()
1 call to AllowedValuesConstraintValidator::getValidChoices()
AllowedValuesConstraintValidator::validate in src/Plugin/Validation/AllowedValuesConstraintValidator.php
Checks if the passed value is valid.

File

src/Plugin/Validation/AllowedValuesConstraintValidator.php, line 89

Class

AllowedValuesConstraintValidator
Validates the AllowedValues constraint.

Namespace

Drupal\select_or_other\Plugin\Validation

Code

private function getValidChoices(TypedDataInterface $typed_data) {
  $allowed_options = [];
  if ($typed_data instanceof ListItemBase) {
    $field_name = $typed_data
      ->getFieldDefinition()
      ->getName();
    $entity_type = $typed_data
      ->getFieldDefinition()
      ->getTargetEntityTypeId();
    $field_storage_definition = FieldStorageConfig::loadByName($entity_type, $field_name);
    $allowed_options = options_allowed_values($field_storage_definition, $typed_data
      ->getEntity());
  }
  return OptGroup::flattenOptions($allowed_options);
}