class MenuTreeHierarchyConstraintValidator in Drupal 10
Same name and namespace in other branches
- 8 core/modules/menu_link_content/src/Plugin/Validation/Constraint/MenuTreeHierarchyConstraintValidator.php \Drupal\menu_link_content\Plugin\Validation\Constraint\MenuTreeHierarchyConstraintValidator
- 9 core/modules/menu_link_content/src/Plugin/Validation/Constraint/MenuTreeHierarchyConstraintValidator.php \Drupal\menu_link_content\Plugin\Validation\Constraint\MenuTreeHierarchyConstraintValidator
Constraint validator for changing menu link parents in pending revisions.
Hierarchy
- class \Drupal\menu_link_content\Plugin\Validation\Constraint\MenuTreeHierarchyConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator implements ContainerInjectionInterface
Expanded class hierarchy of MenuTreeHierarchyConstraintValidator
File
- core/
modules/ menu_link_content/ src/ Plugin/ Validation/ Constraint/ MenuTreeHierarchyConstraintValidator.php, line 14
Namespace
Drupal\menu_link_content\Plugin\Validation\ConstraintView source
class MenuTreeHierarchyConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
private $entityTypeManager;
/**
* Creates a new MenuTreeHierarchyConstraintValidator instance.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function validate($entity, Constraint $constraint) {
if ($entity && !$entity
->isNew() && !$entity
->isDefaultRevision()) {
$original = $this->entityTypeManager
->getStorage($entity
->getEntityTypeId())
->loadUnchanged($entity
->id());
// Ensure that empty items do not affect the comparison checks below.
// @todo Remove this filtering when
// https://www.drupal.org/project/drupal/issues/3039031 is fixed.
$entity->parent
->filterEmptyItems();
if ($entity->parent
->isEmpty() !== $original->parent
->isEmpty() || !$entity->parent
->equals($original->parent)) {
$this->context
->buildViolation($constraint->message)
->atPath('menu_parent')
->addViolation();
}
if (!$entity->weight
->equals($original->weight)) {
$this->context
->buildViolation($constraint->message)
->atPath('weight')
->addViolation();
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MenuTreeHierarchyConstraintValidator:: |
private | property | The entity type manager. | |
MenuTreeHierarchyConstraintValidator:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
MenuTreeHierarchyConstraintValidator:: |
public | function | ||
MenuTreeHierarchyConstraintValidator:: |
public | function | Creates a new MenuTreeHierarchyConstraintValidator instance. |