class UserIdConstraintValidator in Scheduled Updates 8
Hierarchy
- class \Drupal\scheduled_updates_tests\Plugin\Validation\Constraint\UserIdConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of UserIdConstraintValidator
1 file declares its use of UserIdConstraintValidator
- EmbeddedScheduledUpdateTypeTestBase.php in tests/
src/ FunctionalJavascript/ EmbeddedScheduledUpdateTypeTestBase.php - Contains \Drupal\Tests\scheduled_updates\EmbeddedScheduledUpdateTypeTestBase.
File
- tests/
modules/ scheduled_updates_tests/ src/ Plugin/ Validation/ Constraint/ UserIdConstraintValidator.php, line 8
Namespace
Drupal\scheduled_updates_tests\Plugin\Validation\ConstraintView source
class UserIdConstraintValidator extends ConstraintValidator {
const CONSTRAINT_NONE = 'CONSTRAINT_NONE';
const CONSTRAINT_ANONYMOUS = 'CONSTRAINT_ANONYMOUS';
const CONSTRAINT_USER_1 = 'CONSTRAINT_USER_1';
/**
* {@inheritdoc}
*/
public function validate($items, Constraint $constraint) {
/** @var \Drupal\Core\Field\FieldItemListInterface $items */
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $items
->getParent()
->getValue();
if ($entity
->getEntityTypeId() !== 'node') {
return;
}
$constraint = \Drupal::state()
->get('constraint_uid', static::CONSTRAINT_NONE);
if ($constraint !== static::CONSTRAINT_NONE) {
if ($constraint === static::CONSTRAINT_USER_1 && (int) \Drupal::currentUser()
->id() !== 1) {
throw new \LogicException("Only uid 1 validates");
}
elseif ($constraint === static::CONSTRAINT_ANONYMOUS && !\Drupal::currentUser()
->isAnonymous()) {
throw new \LogicException("Only uid 1 validates");
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UserIdConstraintValidator:: |
constant | |||
UserIdConstraintValidator:: |
constant | |||
UserIdConstraintValidator:: |
constant | |||
UserIdConstraintValidator:: |
public | function | Checks if the passed value is valid. |