From 14639d4b1f3524daca883d6148f05524daa55049 Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Mon, 25 Nov 2024 07:43:04 -0600 Subject: [PATCH] VACMS-19570: Adds Section validator --- .../EventSubscriber/ManilaEventSubscriber.php | 2 +- .../Constraint/ManilaSectionListParity.php | 26 ++++++++++ .../ManilaSectionListParityValidator.php | 50 +++++++++++++++++++ .../custom/va_gov_manila/va_gov_manila.module | 26 ++++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 docroot/modules/custom/va_gov_manila/src/Plugin/Validation/Constraint/ManilaSectionListParity.php create mode 100644 docroot/modules/custom/va_gov_manila/src/Plugin/Validation/Constraint/ManilaSectionListParityValidator.php create mode 100644 docroot/modules/custom/va_gov_manila/va_gov_manila.module diff --git a/docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaEventSubscriber.php b/docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaEventSubscriber.php index ea08f51767..e9147e6020 100644 --- a/docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaEventSubscriber.php +++ b/docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaEventSubscriber.php @@ -129,7 +129,7 @@ public function entityUpdate(EntityUpdateEvent $event): void { } /** - * Disable pathauto for Lovell nodes. + * Disable pathauto for Manila nodes. * * @param \Drupal\Core\Entity\EntityInterface $entity * Entity. diff --git a/docroot/modules/custom/va_gov_manila/src/Plugin/Validation/Constraint/ManilaSectionListParity.php b/docroot/modules/custom/va_gov_manila/src/Plugin/Validation/Constraint/ManilaSectionListParity.php new file mode 100644 index 0000000000..9dbef6eaa0 --- /dev/null +++ b/docroot/modules/custom/va_gov_manila/src/Plugin/Validation/Constraint/ManilaSectionListParity.php @@ -0,0 +1,26 @@ +%fieldLabel is not part of the %section section. Please choose a different option or change the section settings to match.'; + +} diff --git a/docroot/modules/custom/va_gov_manila/src/Plugin/Validation/Constraint/ManilaSectionListParityValidator.php b/docroot/modules/custom/va_gov_manila/src/Plugin/Validation/Constraint/ManilaSectionListParityValidator.php new file mode 100644 index 0000000000..05952cae40 --- /dev/null +++ b/docroot/modules/custom/va_gov_manila/src/Plugin/Validation/Constraint/ManilaSectionListParityValidator.php @@ -0,0 +1,50 @@ +getEntity(); + $sectionTermID = $entity->field_administration->target_id; + $fieldLabel = $items->getFieldDefinition()->getLabel(); + if ($sectionTermID === $this->manilaVaSystemId) { + $node_storage = \Drupal::entityTypeManager()->getStorage('node'); + $term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); + $sectionName = $term_storage->load($sectionTermID)->getName(); + foreach ($items as $item) { + /** @var \Drupal\va_gov_manila\Plugin\Validation\Constraint\ManilaSectionListParity $constraint */ + $listPage = $node_storage->load($item->target_id); + if ($listPage->field_administration->target_id !== $sectionTermID) { + $this->context->addViolation($constraint->notSectionListMatch, [ + '%section' => $sectionName, + '%fieldLabel' => $fieldLabel, + ]); + return; + } + } + } + } + +} diff --git a/docroot/modules/custom/va_gov_manila/va_gov_manila.module b/docroot/modules/custom/va_gov_manila/va_gov_manila.module new file mode 100644 index 0000000000..23127f9769 --- /dev/null +++ b/docroot/modules/custom/va_gov_manila/va_gov_manila.module @@ -0,0 +1,26 @@ +id() === 'node') + && (in_array($bundle, $list_item_bundles)) + && (isset($fields['field_listing'])) + && (isset($fields['field_administration']))) { + // Limit the listing selection based on section. + $fields['field_listing']->addConstraint('ManilaSectionListParity'); + } +}