forked from department-of-veterans-affairs/va.gov-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VACMS-13852: Creates EntityEvent Subscriber. (department-of-veterans-…
…affairs#14337) * VACMS-13852: Creates EntityEvent Subscriber. * Tweaks to prevent test failures. * Yeah, no clue what I'm going to do here. * Test all event types. * Adds unit test coverage for LocalFilesystemBuildFileTest. * Test coverage. * Fix trait. * IsFacilityTraitTest. * Ignore coverage on plugin managers and plugin base classes. * Unit tests for the OnDemand entity event strategy plugin. * Make internal logic a little more consistent. * Disable current Entity Event Subscriber 👀 * Adds VerboseFalse entity event strategy plugin. * Oops, my plugins didn't have a logger 😧 * Adds mocks for OnDemand test. * Tests for VerboseFalse. * ContentReleaseTriggerTrait::hasTriggeringChanges() did the Bad Thing™ * D'oh. * Fixes test. * Fix tests. * VerboseFalse and tests. * Specify an exception occurred when getting a node detail threw. * Further tweaks. * Ugh, I'm an idiot. * Updates to VerboseFalse and VerboseFalseTest to support better debugging messages. * Removes bypass from test. * 'exception occurred' => 'Not Applicable'
- Loading branch information
Showing
59 changed files
with
2,829 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
docroot/modules/custom/va_gov_content_release/src/EventSubscriber/EntityEventSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace Drupal\va_gov_content_release\EventSubscriber; | ||
|
||
use Drupal\core_event_dispatcher\EntityHookEvents; | ||
use Drupal\core_event_dispatcher\Event\Entity\AbstractEntityEvent; | ||
use Drupal\va_gov_content_release\EntityEvent\Strategy\Plugin\StrategyPluginManagerInterface; | ||
use Drupal\va_gov_content_release\EntityEvent\Strategy\Resolver\ResolverInterface; | ||
use Drupal\va_gov_content_release\Request\RequestInterface; | ||
use Drupal\va_gov_content_types\Entity\VaNodeInterface; | ||
|
||
/** | ||
* Listens and responds to entity change events by (maybe) releasing content. | ||
*/ | ||
class EntityEventSubscriber implements EntityEventSubscriberInterface { | ||
|
||
/** | ||
* The strategy plugin manager. | ||
* | ||
* @var \Drupal\va_gov_content_release\EntityEvent\Strategy\Plugin\StrategyPluginManagerInterface | ||
*/ | ||
protected $strategyPluginManager; | ||
|
||
/** | ||
* The strategy resolver. | ||
* | ||
* @var \Drupal\va_gov_content_release\EntityEvent\Strategy\Resolver\ResolverInterface | ||
*/ | ||
protected $strategyResolver; | ||
|
||
/** | ||
* The content release request service. | ||
* | ||
* @var \Drupal\va_gov_content_release\Request\RequestInterface | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \Drupal\va_gov_content_release\EntityEvent\Strategy\Plugin\StrategyPluginManagerInterface $strategyPluginManager | ||
* The strategy plugin manager. | ||
* @param \Drupal\va_gov_content_release\EntityEvent\Strategy\Resolver\ResolverInterface $strategyResolver | ||
* The strategy resolver. | ||
* @param \Drupal\va_gov_content_release\Request\RequestInterface $request | ||
* The content release request service. | ||
*/ | ||
public function __construct( | ||
StrategyPluginManagerInterface $strategyPluginManager, | ||
ResolverInterface $strategyResolver, | ||
RequestInterface $request | ||
) { | ||
$this->strategyPluginManager = $strategyPluginManager; | ||
$this->strategyResolver = $strategyResolver; | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents(): array { | ||
return [ | ||
EntityHookEvents::ENTITY_INSERT => 'onInsert', | ||
EntityHookEvents::ENTITY_UPDATE => 'onUpdate', | ||
EntityHookEvents::ENTITY_DELETE => 'onDelete', | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function onInsert(AbstractEntityEvent $event) : void { | ||
$entity = $event->getEntity(); | ||
if ($entity instanceof VaNodeInterface) { | ||
$this->handleNodeUpdate($entity); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function onUpdate(AbstractEntityEvent $event) : void { | ||
$entity = $event->getEntity(); | ||
if ($entity instanceof VaNodeInterface) { | ||
$this->handleNodeUpdate($entity); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function onDelete(AbstractEntityEvent $event) : void { | ||
$entity = $event->getEntity(); | ||
if ($entity instanceof VaNodeInterface) { | ||
$this->handleNodeUpdate($entity); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function handleNodeUpdate(VaNodeInterface $node) : void { | ||
$strategyId = $this->strategyResolver->getStrategyId(); | ||
$strategy = $this->strategyPluginManager->getStrategy($strategyId); | ||
if ($strategy->shouldTriggerContentRelease($node)) { | ||
$reason = $strategy->getReasonMessage($node); | ||
$this->request->submitRequest($reason); | ||
} | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...ules/custom/va_gov_content_release/src/EventSubscriber/EntityEventSubscriberInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Drupal\va_gov_content_release\EventSubscriber; | ||
|
||
use Drupal\core_event_dispatcher\Event\Entity\AbstractEntityEvent; | ||
use Drupal\va_gov_content_types\Entity\VaNodeInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Listens and responds to entity change events by (maybe) releasing content. | ||
*/ | ||
interface EntityEventSubscriberInterface extends EventSubscriberInterface { | ||
|
||
/** | ||
* Handle entity insert events. | ||
* | ||
* @param \Drupal\core_event_dispatcher\Event\Entity\AbstractEntityEvent $event | ||
* The event object passed by the event dispatcher. | ||
*/ | ||
public function onInsert(AbstractEntityEvent $event) : void; | ||
|
||
/** | ||
* Handle entity update events. | ||
* | ||
* @param \Drupal\core_event_dispatcher\Event\Entity\AbstractEntityEvent $event | ||
* The event object passed by the event dispatcher. | ||
*/ | ||
public function onUpdate(AbstractEntityEvent $event) : void; | ||
|
||
/** | ||
* Handle entity delete events. | ||
* | ||
* @param \Drupal\core_event_dispatcher\Event\Entity\AbstractEntityEvent $event | ||
* The event object passed by the event dispatcher. | ||
*/ | ||
public function onDelete(AbstractEntityEvent $event) : void; | ||
|
||
/** | ||
* Handle entity updates for a specific node. | ||
* | ||
* @param \Drupal\va_gov_content_types\Entity\VaNodeInterface $node | ||
* The node to check for updates. | ||
*/ | ||
public function handleNodeUpdate(VaNodeInterface $node) : void; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.