class TestContinuousEventSubscriber in Translation Management Tool 8
Test event subscriber to test the continuous jobs events.
Hierarchy
- class \Drupal\tmgmt_test\EventSubscriber\TestContinuousEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of TestContinuousEventSubscriber
1 file declares its use of TestContinuousEventSubscriber
- ContentEntitySourceUnitTest.php in sources/
content/ tests/ src/ Kernel/ ContentEntitySourceUnitTest.php
1 string reference to 'TestContinuousEventSubscriber'
- tmgmt_test.services.yml in tmgmt_test/
tmgmt_test.services.yml - tmgmt_test/tmgmt_test.services.yml
1 service uses TestContinuousEventSubscriber
File
- tmgmt_test/
src/ EventSubscriber/ TestContinuousEventSubscriber.php, line 13
Namespace
Drupal\tmgmt_test\EventSubscriberView source
class TestContinuousEventSubscriber implements EventSubscriberInterface {
/**
* Label that prevents a node from being added.
*/
const DISALLOWED_LABEL = 'Testing SHOULD_CREATE_JOB event';
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* TestContinuousEventSubscriber constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* Do not add the job if we have a filter match.
*
* @param \Drupal\tmgmt\Events\ShouldCreateJobEvent $event
* The event object.
*/
public function onShouldCreateJob(ShouldCreateJobEvent $event) {
// Filter out content.
if ($event
->getPlugin() === 'content') {
$storage = $this->entityTypeManager
->getStorage($event
->getItemType());
$entity = $storage
->load($event
->getItemId());
if ($entity
->label() === static::DISALLOWED_LABEL) {
$event
->setShouldCreateItem(FALSE);
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ContinuousEvents::SHOULD_CREATE_JOB][] = [
'onShouldCreateJob',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TestContinuousEventSubscriber:: |
protected | property | ||
TestContinuousEventSubscriber:: |
constant | Label that prevents a node from being added. | ||
TestContinuousEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
TestContinuousEventSubscriber:: |
public | function | Do not add the job if we have a filter match. | |
TestContinuousEventSubscriber:: |
public | function | TestContinuousEventSubscriber constructor. |