You are here

public function SchedulerPublishSubScriber::onNodePublish in Content Planner 8

Act upon a node publish.

Parameters

\Drupal\scheduler\SchedulerEvent $event:

File

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

Class

SchedulerPublishSubScriber

Namespace

Drupal\content_calendar\EventSubscriber

Code

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);
  }
}