class ValidOgMembershipReferenceConstraintValidator in Organic groups 8
Checks if referenced entities are valid.
Hierarchy
- class \Drupal\og\Plugin\Validation\Constraint\ValidOgMembershipReferenceConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of ValidOgMembershipReferenceConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ ValidOgMembershipReferenceConstraintValidator.php, line 14
Namespace
Drupal\og\Plugin\Validation\ConstraintView source
class ValidOgMembershipReferenceConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) {
/** @var \Drupal\Core\Field\FieldItemInterface $value */
if (!isset($value)) {
return;
}
$entity = \Drupal::entityTypeManager()
->getStorage($value
->getFieldDefinition()
->getFieldStorageDefinition()
->getSetting('target_type'))
->load($value
->get('target_id')
->getValue());
if (!$entity) {
// Entity with that entity ID does not exists. This could happen if a
// stale entity is passed for validation.
return;
}
$params['%label'] = $entity
->label();
if (!Og::isGroup($entity
->getEntityTypeId(), $entity
->bundle())) {
$this->context
->addViolation($constraint->notValidGroup, $params);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ValidOgMembershipReferenceConstraintValidator:: |
public | function | Checks if the passed value is valid. |