Skip to content

Commit

Permalink
Merge branch 'main' into VACMS-19227-manila-ph-added-to-us
Browse files Browse the repository at this point in the history
  • Loading branch information
omahane authored Dec 19, 2024
2 parents 51bf2a5 + c967f4d commit 719ff4a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 59 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
"symfony/phpunit-bridge": "^7.1",
"symfony/process": "^6.3",
"symfony/routing": "^6.3",
"va-gov/content-build": "^0.0.3651",
"va-gov/content-build": "^0.0.3653",
"vlucas/phpdotenv": "^5.6",
"webflo/drupal-finder": "1.3.1",
"webmozart/path-util": "^2.3",
Expand Down
22 changes: 11 additions & 11 deletions composer.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3cd3f7a9eb318a034ebda92c45809a33",
"content-hash": "2a39c20150ecdc1f7f9b627eaec6f791",
"packages": [
{
"name": "asm89/stack-cors",
Expand Down Expand Up @@ -26666,16 +26666,16 @@
},
{
"name": "va-gov/content-build",
"version": "v0.0.3651",
"version": "v0.0.3653",
"source": {
"type": "git",
"url": "https://github.com/department-of-veterans-affairs/content-build.git",
"reference": "46e0d59db34626ec5a54fe7d07a44edc431320f4"
"reference": "bebe2c2276d09c13500dc860a272ce6f7b641943"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/department-of-veterans-affairs/content-build/zipball/46e0d59db34626ec5a54fe7d07a44edc431320f4",
"reference": "46e0d59db34626ec5a54fe7d07a44edc431320f4",
"url": "https://api.github.com/repos/department-of-veterans-affairs/content-build/zipball/bebe2c2276d09c13500dc860a272ce6f7b641943",
"reference": "bebe2c2276d09c13500dc860a272ce6f7b641943",
"shasum": ""
},
"type": "node-project",
Expand All @@ -26702,9 +26702,9 @@
"description": "Front-end for VA.gov. This repository contains the code that generates the www.va.gov website. It contains a Metalsmith static site builder that uses a Drupal CMS for content. This file is here to publish releases to https://packagist.org/packages/va-gov/content-build, so that the CMS CI system can install it and update it using standard composer processes, and so that we can run tests across both systems. See https://github.com/department-of-veterans-affairs/va.gov-cms for the CMS repo, and stand by for more documentation.",
"support": {
"issues": "https://github.com/department-of-veterans-affairs/content-build/issues",
"source": "https://github.com/department-of-veterans-affairs/content-build/tree/v0.0.3651"
"source": "https://github.com/department-of-veterans-affairs/content-build/tree/v0.0.3653"
},
"time": "2024-12-16T18:37:47+00:00"
"time": "2024-12-17T18:58:38+00:00"
},
{
"name": "vlucas/phpdotenv",
Expand Down Expand Up @@ -27710,7 +27710,6 @@
"drupal/fieldhelptext": 10,
"drupal/flag": 10,
"drupal/graphql_menu": 15,
"drupal/html_tag_usage": 10,
"drupal/image_style_warmer": 5,
"drupal/jsonapi_resources": 10,
"drupal/limited_field_widgets": 15,
Expand All @@ -27729,12 +27728,13 @@
"drupal/simplesamlphp_auth": 5,
"drupal/styleguide": 10,
"drupal/user_history": 15,
"drupal/viewfield": 10
"drupal/viewfield": 10,
"drupal/html_tag_usage": 10
},
"prefer-stable": true,
"prefer-lowest": false,
"platform": {},
"platform-dev": {},
"platform": [],
"platform-dev": [],
"platform-overrides": {
"php": "8.1.30"
},
Expand Down
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 719ff4a

Please sign in to comment.