You are here

class ImportSubscriber in Thunder 8.2

Class ImportSubscriber.

Hierarchy

  • class \Drupal\thunder_demo\EventSubscriber\ImportSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ImportSubscriber

1 string reference to 'ImportSubscriber'
thunder_demo.services.yml in modules/thunder_demo/thunder_demo.services.yml
modules/thunder_demo/thunder_demo.services.yml
1 service uses ImportSubscriber
thunder_demo.import_subscriber in modules/thunder_demo/thunder_demo.services.yml
Drupal\thunder_demo\EventSubscriber\ImportSubscriber

File

modules/thunder_demo/src/EventSubscriber/ImportSubscriber.php, line 12

Namespace

Drupal\thunder_demo\EventSubscriber
View source
class ImportSubscriber implements EventSubscriberInterface {

  /**
   * Publish imported articles.
   *
   * @param \Drupal\default_content\Event\ImportEvent $event
   *   The event entity.
   *
   * @throws \Drupal\Core\Entity\EntityStorageException
   */
  public function onImport(ImportEvent $event) {
    $uuids = [
      '0bd5c257-2231-450f-b4c2-ab156af7b78d',
      '36b2e2b2-3df0-43eb-a282-d792b0999c07',
      '94ad928b-3ec8-4bcb-b617-ab1607bf69cb',
      'bbb1ee17-15f8-46bd-9df5-21c58040d741',
    ];
    foreach ($event
      ->getImportedEntities() as $entity) {
      if (in_array($entity
        ->uuid(), $uuids)) {
        $entity->moderation_state->value = 'published';
        $entity
          ->save();
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[DefaultContentEvents::IMPORT][] = [
      'onImport',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ImportSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ImportSubscriber::onImport public function Publish imported articles.