headless_cms-1.0.3/modules/headless_cms_notify/src/EventSubscriber/HeadlessNotifyEventSubscriber.php

modules/headless_cms_notify/src/EventSubscriber/HeadlessNotifyEventSubscriber.php
<?php

declare(strict_types=1);

namespace Drupal\headless_cms_notify\EventSubscriber;

use Drupal\Core\State\StateInterface;
use Drupal\headless_cms_notify\Event\BeforeHeadlessNotifyEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\migrate_utils\MigrateState;

/**
 * Event subscriber for the headless notify module.
 */
class HeadlessNotifyEventSubscriber implements EventSubscriberInterface {

  public function __construct(
    protected readonly StateInterface $state,
  ) {}

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents(): array {
    return [
      BeforeHeadlessNotifyEvent::EVENT_NAME => ['onBeforeHeadlessNotify'],
    ];
  }

  /**
   * Handles the before headless notify event.
   */
  public function onBeforeHeadlessNotify(BeforeHeadlessNotifyEvent $event) {
    if (!$this->shouldHandle()) {
      return;
    }

    // Abort if migration is running.
    if (MigrateState::isMigrationRunning()) {
      $event->abort();
    }
  }

  /**
   * Checks if the event should be handled.
   */
  protected function shouldHandle(): bool {
    return class_exists(MigrateState::class) && !$this->state->get('headless_cms_notify.enable_notify_on_migrate', FALSE);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc