Skip to content

Commit

Permalink
Add a state setting to stop next revalidation events if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Dec 2, 2024
1 parent 93394bb commit 7267ae4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Drupal\stanford_decoupled\EventSubscriber;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\next\Event\EntityActionEvent;
use Drupal\next\Event\EntityEvents;
use Drupal\stanford_profile_helper\Event\MenuCacheEvent;
Expand Down Expand Up @@ -33,7 +34,7 @@ public static function getSubscribedEvents(): array {
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* Entity type manager service.
*/
public function __construct(protected EntityTypeManagerInterface $entityTypeManager) {}
public function __construct(protected EntityTypeManagerInterface $entityTypeManager, protected StateInterface $state) {}

/**
* Stop propagation of the event if on local environment and CLI execution.
Expand All @@ -42,6 +43,10 @@ public function __construct(protected EntityTypeManagerInterface $entityTypeMana
* Next module event.
*/
public function onNextEntityAction(EntityActionEvent $event) {
if ($this->state->get('stanford_decoupled.stop_propagation', FALSE)) {
$event->stopPropagation();
}

// When the site is not on an Acquia environment and running via the CLI, we
// don't need to do any invalidations. This is often for migration runs.
if (!getenv('AH_SITE_ENVIRONMENT') && !getenv('PANTHEON_ENVIRONMENT') && PHP_SAPI == 'cli') {
Expand Down
2 changes: 1 addition & 1 deletion modules/stanford_decoupled/stanford_decoupled.services.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
stanford_decoupled.event_subscriber:
class: Drupal\stanford_decoupled\EventSubscriber\DecoupledEventSubscriber
arguments: ['@entity_type.manager']
arguments: ['@entity_type.manager', '@state']
tags:
- { name: event_subscriber }
stanford_decoupled.config_overrider:
Expand Down

0 comments on commit 7267ae4

Please sign in to comment.