You are here

class SchedulerPublishSubScriber in Content Planner 8

Hierarchy

  • class \Drupal\content_calendar\EventSubscriber\SchedulerPublishSubScriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of SchedulerPublishSubScriber

1 string reference to 'SchedulerPublishSubScriber'
content_calendar.services.yml in modules/content_calendar/content_calendar.services.yml
modules/content_calendar/content_calendar.services.yml
1 service uses SchedulerPublishSubScriber
content_calendar.scheduler_publish_subscriber in modules/content_calendar/content_calendar.services.yml
Drupal\content_calendar\EventSubscriber\SchedulerPublishSubScriber

File

modules/content_calendar/src/EventSubscriber/SchedulerPublishSubScriber.php, line 12

Namespace

Drupal\content_calendar\EventSubscriber
View source
class SchedulerPublishSubScriber implements EventSubscriberInterface {

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

    // The values in the arrays give the function names below.
    $events[SchedulerEvents::PUBLISH][] = [
      'onNodePublish',
    ];
    return $events;
  }

  /**
   * Act upon a node publish.
   *
   * @param \Drupal\scheduler\SchedulerEvent $event
   */
  public function onNodePublish(SchedulerEvent $event) {

    // If the Content Kanban module exists.
    if (\Drupal::moduleHandler()
      ->moduleExists('content_kanban')) {

      /** @var \Drupal\node\Entity\Node $node */
      $node = $event
        ->getNode();

      // Set status to published.
      $node
        ->setPublished(TRUE);

      // Set Moderation state to published.
      $node->moderation_state->value = 'published';

      // Return updated node to event which in turn returns it to the scheduler module.
      $event
        ->setNode($node);
    }
  }

}

Members