You are here

class SchedulerEventSubscriber in Scheduler content moderation integration 8

Handle scheduler events.

The six possible Scheduler events are: SchedulerEvents::PRE_PUBLISH SchedulerEvents::PUBLISH SchedulerEvents::PRE_UNPUBLISH SchedulerEvents::UNPUBLISH SchedulerEvents::PRE_PUBLISH_IMMEDIATELY SchedulerEvents::PUBLISH_IMMEDIATELY.

Hierarchy

  • class \Drupal\scheduler_content_moderation_integration\EventSubscriber\SchedulerEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of SchedulerEventSubscriber

1 string reference to 'SchedulerEventSubscriber'
scheduler_content_moderation_integration.services.yml in ./scheduler_content_moderation_integration.services.yml
scheduler_content_moderation_integration.services.yml
1 service uses SchedulerEventSubscriber
scheduler_content_moderation_integration.scheduler_event_subscriber in ./scheduler_content_moderation_integration.services.yml
Drupal\scheduler_content_moderation_integration\EventSubscriber\SchedulerEventSubscriber

File

src/EventSubscriber/SchedulerEventSubscriber.php, line 20

Namespace

Drupal\scheduler_content_moderation_integration\EventSubscriber
View source
class SchedulerEventSubscriber implements EventSubscriberInterface {

  /**
   * Operations to perform after Scheduler publishes a node immediately.
   *
   * This is during the edit process, not via cron.
   *
   * @param \Drupal\scheduler\SchedulerEvent $event
   *   The event being acted on.
   */
  public function publishImmediately(SchedulerEvent $event) {

    /** @var \Drupal\node\Entity\Node $node */
    $node = $event
      ->getNode();
    $node
      ->set('moderation_state', $node->publish_state
      ->getValue());
    $event
      ->setNode($node);
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {

    // The values in the arrays give the function names above.
    $events[SchedulerEvents::PUBLISH_IMMEDIATELY][] = [
      'publishImmediately',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SchedulerEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
SchedulerEventSubscriber::publishImmediately public function Operations to perform after Scheduler publishes a node immediately.