Skip to content

Commit

Permalink
Merge branch 'main' into VACMS-19369-notify-tic-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
omahane authored Dec 19, 2024
2 parents 74bfa96 + e42acf3 commit be9e3c1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Original file line number Diff line number Diff line change
@@ -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)
);

0 comments on commit be9e3c1

Please sign in to comment.