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 1ea0394b85..435fd8d76d 100644 --- a/docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaEventSubscriber.php +++ b/docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaEventSubscriber.php @@ -10,7 +10,6 @@ use Drupal\core_event_dispatcher\EntityHookEvents; use Drupal\core_event_dispatcher\Event\Entity\EntityBundleFieldInfoAlterEvent; use Drupal\core_event_dispatcher\Event\Entity\EntityInsertEvent; -use Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent; use Drupal\core_event_dispatcher\Event\Entity\EntityUpdateEvent; use Drupal\node\NodeInterface; use Drupal\path_alias\Entity\PathAlias; @@ -91,23 +90,11 @@ public function __construct( public static function getSubscribedEvents(): array { return [ EntityHookEvents::ENTITY_INSERT => 'entityInsert', - EntityHookEvents::ENTITY_PRE_SAVE => 'entityPresave', EntityHookEvents::ENTITY_UPDATE => 'entityUpdate', EntityHookEvents::ENTITY_BUNDLE_FIELD_INFO_ALTER => 'alterFieldInfo', ]; } - /** - * Entity presave Event call. - * - * @param \Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent $event - * The event. - */ - public function entityPresave(EntityPresaveEvent $event): void { - $entity = $event->getEntity(); - $this->blockManilaPathauto($entity); - } - /** * Entity insert Event call. * @@ -164,27 +151,6 @@ public function alterFieldInfo(EntityBundleFieldInfoAlterEvent $event): void { } } - /** - * Disable pathauto for Manila nodes. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * Entity. - */ - protected function blockManilaPathauto(EntityInterface $entity): void { - if (($entity instanceof NodeInterface) - && ($entity->hasField('path')) - && ($entity->hasField('field_administration'))) { - $section_id = $entity->get('field_administration')->target_id; - if ($section_id !== $this->manilaVaSystemId) { - return; - } - - // If this node is in a Manila section disable pathauto pattern. - // @phpstan-ignore-next-line - $entity->path->pathauto = 0; - } - } - /** * Update path aliases for Manila content. * @@ -237,21 +203,34 @@ protected function updatePathAliases(EntityInterface $entity): void { * An array of Pathalias objects. */ protected function generateValidAliases(array $prefixes, NodeInterface $node): array { - $new_url = $this->pathautoGenerator->createEntityAlias($node, 'return'); - $url_pieces = explode('/', $new_url); - $new_aliases = []; - foreach ($prefixes as $prefix) { - // Replace the first segment and use the rest. - $url = "/{$prefix}/" . implode('/', array_slice($url_pieces, 2)); - // Remove trailing -0 from using the menu parent for VAMC detail pages. - // This also applies to leadership pages. - $url = preg_replace('/-0$/', '', $url); + // If this is a Manila VA Clinic node use a specific alias. + $bundle_type = $node->bundle(); + if ($bundle_type === 'health_care_local_facility') { $new_alias = PathAlias::Create([ 'path' => "/node/{$node->id()}", - 'alias' => $url, + 'alias' => '/manila-va-clinic', 'langcode' => $node->language()->getId(), ]); - $new_aliases[] = $new_alias; + $new_aliases = [$new_alias]; + } + else { + // Use the Pathauto module alias pattern for all other content types. + $new_url = $this->pathautoGenerator->createEntityAlias($node, 'return'); + $url_pieces = explode('/', $new_url); + $new_aliases = []; + foreach ($prefixes as $prefix) { + // Replace the first segment and use the rest. + $url = "/{$prefix}/" . implode('/', array_slice($url_pieces, 2)); + // Remove trailing -0 from using the menu parent for VAMC detail pages. + // This also applies to leadership pages. + $url = preg_replace('/-0$/', '', $url); + $new_alias = PathAlias::Create([ + 'path' => "/node/{$node->id()}", + 'alias' => $url, + 'langcode' => $node->language()->getId(), + ]); + $new_aliases[] = $new_alias; + } } return $new_aliases; } diff --git a/tests/cypress/integration/features/content_type/facilities/manila.feature b/tests/cypress/integration/features/content_type/facilities/manila.feature index ce03ef5d8b..636e98d084 100644 --- a/tests/cypress/integration/features/content_type/facilities/manila.feature +++ b/tests/cypress/integration/features/content_type/facilities/manila.feature @@ -1,5 +1,5 @@ -@content_type__event -Feature: Content Type: Event +@content_type__event, @content_editing_vamc_facility +Feature: Content Types: Event, VAMC Facility Scenario: Log in and create Event as a Manila editor When I am logged in as a user with the roles "vamc_content_creator, content_publisher" @@ -18,3 +18,12 @@ Scenario: Log in and create Event as a Manila editor And I fill in "Revision log message" with "[TEST] Revision log message" And I click the "Save" button Then I should be at "manila-va-clinic" + +Scenario: Log in and edit the Manila VA Clinic + When I am logged in as a user with the roles "vamc_content_creator, content_publisher" + And my workbench access sections are set to "1187" + Then I am at "/node/1059/edit" + And I select option "Published" from dropdown "Save as" + And I fill in "Revision log message" with "[TEST] Revision log message" + And I click the "Save" button + Then I should not be at "/manila-va-clinic/locations/manila-va-clinic" \ No newline at end of file diff --git a/tests/cypress/integration/step_definitions/common/i_should_be_at_url.js b/tests/cypress/integration/step_definitions/common/i_should_be_at_url.js index 33a5c014e5..f047b34a89 100644 --- a/tests/cypress/integration/step_definitions/common/i_should_be_at_url.js +++ b/tests/cypress/integration/step_definitions/common/i_should_be_at_url.js @@ -1,3 +1,7 @@ import { Then } from "@badeball/cypress-cucumber-preprocessor"; Then(`I should be at {string}`, (url) => cy.url().should("include", url)); + +Then(`I should not be at {string}`, (url) => + cy.url().should("not.include", url) +);