This question already has an answer here:

On we create article we have 'Save' & 'Preview' button.

I would like to add 'Save as draft' button.

I found https://www.drupal.org/project/save_draft But it's not for Drupal 8

Found this URL : https://sites.google.com/site/learnandmake/how-to-created-button-for-each-state-of-workflow-in-drupal-7

I tried with this

function custom_module_form_node_form_alter(&$form, FormStateInterface $form_state) {
  $form['actions']['draft'] = array(
    '#type' => 'submit',
    '#class' => 'form-submit',
    '#name' => 'btn-draft',
    '#value' => t('Save as draft'),
    '#weight' => '-10',
    '#submit' => ['custom_module_node_form_submit']

In the function

function custom_module_node_form_submit(&$form, FormStateInterface $form_state) {

  $button_clicked = $form_state->getTriggeringElement()['#name'];

  if ($button_clicked == 'btn-draft') {
    if ($entity = $form_state->getFormObject()->getEntity()) {
      $entity->set('moderation_state', 'draft');

Using workflow module.

So have state (Draft/Publish/Archive)

Once it save not able to alternative function for node_form_submit($form, $form_state); Currently it's giving error 'title` is missing in DB Query


The website encountered an unexpected error. Please try again later.Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null: INSERT INTO {node_field_data} (nid, vid, type, langcode, status, title, uid, created, changed, promote, sticky, default_langcode, revision_translation_affected, weight, publish_on, unpublish_on, publish_state, unpublish_state) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17);

marked as duplicate by AjitS, leymannx, Alfred Armstrong, mradcliffe, Felix Eve Sep 7 '18 at 7:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Drupal 8 has save as unpublished button for a content. I think this might remove the requirement for Save Draft button. – Shreya Shetty Aug 24 '18 at 5:23
  • @ShreyaShetty Sorry forgot to mention, Using workflow module. So need to save that state – Julia Aug 24 '18 at 5:44
  • @Julia Can you edit the question and mention if you are using the "Workflows" module coming from the core, or the contributed workflow module? – AjitS Aug 24 '18 at 7:37
  • Updates question @AjitS – Julia Aug 24 '18 at 10:09
  • drupal.stackexchange.com/questions/247359/… Got answer – Julia Aug 24 '18 at 16:36

Browse other questions tagged or ask your own question.