/** * Publishes a node. * * @param NodeInterface $node * @return int */ protected function publishNode($node) { $node->setPublished(TRUE); return $node->save(); }
/** * Entity builder updating the node status with the submitted value. * * @param string $entity_type_id * The entity type identifier. * @param \Drupal\node\NodeInterface $node * The node updated with the submitted values. * @param array $form * The complete form array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @see \Drupal\node\NodeForm::form() */ function updateStatus($entity_type_id, NodeInterface $node, array $form, FormStateInterface $form_state) { $element = $form_state->getTriggeringElement(); if (isset($element['#published_status'])) { $node->setPublished($element['#published_status']); } }