class ConfigExistsConstraintValidator
Same name in other branches
- 10 core/lib/Drupal/Core/Config/Plugin/Validation/Constraint/ConfigExistsConstraintValidator.php \Drupal\Core\Config\Plugin\Validation\Constraint\ConfigExistsConstraintValidator
Validates that a given config object exists.
Hierarchy
- class \Drupal\Core\Config\Plugin\Validation\Constraint\ConfigExistsConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface
Expanded class hierarchy of ConfigExistsConstraintValidator
File
-
core/
lib/ Drupal/ Core/ Config/ Plugin/ Validation/ Constraint/ ConfigExistsConstraintValidator.php, line 16
Namespace
Drupal\Core\Config\Plugin\Validation\ConstraintView source
class ConfigExistsConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected ConfigFactoryInterface $configFactory;
/**
* Constructs a ConfigExistsConstraintValidator object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function validate(mixed $name, Constraint $constraint) : void {
assert($constraint instanceof ConfigExistsConstraint);
// This constraint may be used to validate nullable (optional) values.
if ($name === NULL) {
return;
}
if (!in_array($constraint->prefix . $name, $this->configFactory
->listAll($constraint->prefix), TRUE)) {
$this->context
->addViolation($constraint->message, [
'@name' => $constraint->prefix . $name,
]);
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ConfigExistsConstraintValidator::$configFactory | protected | property | The config factory service. | |
ConfigExistsConstraintValidator::create | public static | function | Instantiates a new instance of this class. | Overrides ContainerInjectionInterface::create |
ConfigExistsConstraintValidator::validate | public | function | ||
ConfigExistsConstraintValidator::__construct | public | function | Constructs a ConfigExistsConstraintValidator object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.