class LangcodeRequiredIfTranslatableValuesConstraintValidator
Same name in other branches
- 11.x core/lib/Drupal/Core/Config/Plugin/Validation/Constraint/LangcodeRequiredIfTranslatableValuesConstraintValidator.php \Drupal\Core\Config\Plugin\Validation\Constraint\LangcodeRequiredIfTranslatableValuesConstraintValidator
Validates the LangcodeRequiredIfTranslatableValues constraint.
Hierarchy
- class \Drupal\Core\Config\Plugin\Validation\Constraint\LangcodeRequiredIfTranslatableValuesConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of LangcodeRequiredIfTranslatableValuesConstraintValidator
File
-
core/
lib/ Drupal/ Core/ Config/ Plugin/ Validation/ Constraint/ LangcodeRequiredIfTranslatableValuesConstraintValidator.php, line 14
Namespace
Drupal\Core\Config\Plugin\Validation\ConstraintView source
final class LangcodeRequiredIfTranslatableValuesConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate(mixed $value, Constraint $constraint) : void {
assert($constraint instanceof LangcodeRequiredIfTranslatableValuesConstraint);
$mapping = $this->context
->getObject();
assert($mapping instanceof Mapping);
$root = $this->context
->getRoot();
if ($mapping !== $root) {
@trigger_error(sprintf('The LangcodeRequiredIfTranslatableValues constraint can only be applied to the root object being validated, using the \'config_object\' schema type on \'%s\' is deprecated in drupal:10.3.0 and will trigger a \\LogicException in drupal:11.0.0. See https://www.drupal.org/node/3459863', $root->getName() . '::' . $mapping->getName()), E_USER_DEPRECATED);
return;
}
assert(in_array('langcode', $mapping->getValidKeys(), TRUE));
$is_translatable = $mapping->hasTranslatableElements();
if ($is_translatable && !array_key_exists('langcode', $value)) {
$this->context
->buildViolation($constraint->missingMessage)
->setParameter('@name', $mapping->getName())
->addViolation();
return;
}
if (!$is_translatable && array_key_exists('langcode', $value)) {
// @todo Convert this deprecation to an actual validation error in
// https://www.drupal.org/project/drupal/issues/3440238.
// phpcs:ignore
@trigger_error(str_replace('@name', $mapping->getName(), $constraint->superfluousMessage), E_USER_DEPRECATED);
}
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.