class PushNotificationsTokenLanguageConstraintValidator in Push Notifications 8
Checks if a language code is in the list of accepted language codes.
Hierarchy
- class \Drupal\push_notifications\Plugin\Validation\Constraint\PushNotificationsTokenLanguageConstraintValidator extends \Symfony\Component\Validator\Constraints\ChoiceValidator uses TypedDataAwareValidatorTrait
Expanded class hierarchy of PushNotificationsTokenLanguageConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ PushNotificationsTokenLanguageConstraintValidator.php, line 13
Namespace
Drupal\push_notifications\Plugin\Validation\ConstraintView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PushNotificationsTokenLanguageConstraintValidator:: |
public | function | Checks if the passed value is valid. | |
TypedDataAwareValidatorTrait:: |
public | function | Gets the typed data object for the validated value. |