class ReadonlymodeConstraintValidator in Read only mode 2.0.x
Validator for the Readonlymode constraint.
Hierarchy
- class \Drupal\readonlymode\Plugin\Validation\Constraint\ReadonlymodeConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of ReadonlymodeConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ ReadonlymodeConstraintValidator.php, line 11
Namespace
Drupal\readonlymode\Plugin\Validation\ConstraintView source
class ReadonlymodeConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($items, Constraint $constraint) {
// Here we could do an early return if the user has the permission to update
// content anyway. But it will be lost during the deployment so do we want
// that really?
/** @var \Drupal\readonlymode\ReadonlymodeManager $manager */
$manager = \Drupal::service('readonlymode.manager');
if ($manager
->isReadonly() && PHP_SAPI !== 'cli') {
// Here we could also get the entity from the $items and pass it to the
// manager to get the error tailored to the entity.
$this->context
->addViolation('@readonly_message', [
'@readonly_message' => $manager
->getErrorMessage(),
]);
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ReadonlymodeConstraintValidator:: |
public | function |