You are here

class TestContinuousEventSubscriber in Translation Management Tool 8

Test event subscriber to test the continuous jobs events.

Hierarchy

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
tmgmt_test.should_create_job in tmgmt_test/tmgmt_test.services.yml
Drupal\tmgmt_test\EventSubscriber\TestContinuousEventSubscriber

File

tmgmt_test/src/EventSubscriber/TestContinuousEventSubscriber.php, line 13

Namespace

Drupal\tmgmt_test\EventSubscriber
View 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

Namesort descending Modifiers Type Description Overrides
TestContinuousEventSubscriber::$entityTypeManager protected property
TestContinuousEventSubscriber::DISALLOWED_LABEL constant Label that prevents a node from being added.
TestContinuousEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
TestContinuousEventSubscriber::onShouldCreateJob public function Do not add the job if we have a filter match.
TestContinuousEventSubscriber::__construct public function TestContinuousEventSubscriber constructor.