Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / menu_ui / src / Plugin / Validation / Constraint / MenuSettingsConstraintValidator.php
1 <?php
2
3 namespace Drupal\menu_ui\Plugin\Validation\Constraint;
4
5 use Symfony\Component\Validator\Constraint;
6 use Symfony\Component\Validator\ConstraintValidator;
7
8 /**
9  * Constraint validator for changing the menu settings in pending revisions.
10  */
11 class MenuSettingsConstraintValidator extends ConstraintValidator {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function validate($entity, Constraint $constraint) {
17     if (isset($entity) && !$entity->isNew() && !$entity->isDefaultRevision()) {
18       $defaults = menu_ui_get_menu_link_defaults($entity);
19       $values = $entity->menu;
20       $violation_path = NULL;
21
22       if (trim($values['title']) && !empty($values['menu_parent'])) {
23         list($menu_name, $parent) = explode(':', $values['menu_parent'], 2);
24         $values['menu_name'] = $menu_name;
25         $values['parent'] = $parent;
26       }
27
28       // Handle the case when a menu link is added to a pending revision.
29       if (!$defaults['entity_id'] && $values['enabled']) {
30         $violation_path = 'menu';
31       }
32       // Handle the case when the menu link is deleted in a pending revision.
33       elseif (empty($values['enabled']) && $defaults['entity_id']) {
34         $violation_path = 'menu';
35       }
36       // Handle all the other menu link changes in a pending revision.
37       elseif ($defaults['entity_id']) {
38         if (($values['title'] != $defaults['title'])) {
39           $violation_path = 'menu.title';
40         }
41         elseif (($values['description'] != $defaults['description'])) {
42           $violation_path = 'menu.description';
43         }
44         elseif ($defaults['entity_id'] && ($values['menu_name'] != $defaults['menu_name'])) {
45           $violation_path = 'menu.menu_parent';
46         }
47         elseif (isset($values['parent']) && ($values['parent'] != $defaults['parent'])) {
48           $violation_path = 'menu.menu_parent';
49         }
50         elseif (($values['weight'] != $defaults['weight'])) {
51           $violation_path = 'menu.weight';
52         }
53       }
54
55       if ($violation_path) {
56         $this->context->buildViolation($constraint->message)
57           ->atPath($violation_path)
58           ->setInvalidValue($entity)
59           ->addViolation();
60       }
61     }
62   }
63
64 }