You are here

class PushNotificationsTokenLanguageConstraintValidator in Push Notifications 8

Checks if a language code is in the list of accepted language codes.

Hierarchy

Expanded class hierarchy of PushNotificationsTokenLanguageConstraintValidator

File

src/Plugin/Validation/Constraint/PushNotificationsTokenLanguageConstraintValidator.php, line 13

Namespace

Drupal\push_notifications\Plugin\Validation\Constraint
View source
class PushNotificationsTokenLanguageConstraintValidator extends ChoiceValidator {
  use TypedDataAwareValidatorTrait;

  /**
   * {@inheritdoc}
   */
  public function validate($value, Constraint $constraint) {

    // Determine the language code.
    // Get the data from the typed data list item.
    // @see https://api.drupal.org/api/drupal/core!core.api.php/group/typed_data/8.2.x,
    // Tree handling.
    $typed_data = $this
      ->getTypedData();
    $value = $typed_data->value;

    // Set available choices to all available languages.
    $constraint->choices = array_keys(LanguageManager::getStandardLanguageList());
    parent::validate($value, $constraint);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PushNotificationsTokenLanguageConstraintValidator::validate public function Checks if the passed value is valid.
TypedDataAwareValidatorTrait::getTypedData public function Gets the typed data object for the validated value.