You are here

function addanother_node_form_submit in Add Another 8

Same name and namespace in other branches
  1. 7.2 addanother.module \addanother_node_form_submit()

Submit handler for the 'Save and add another' button.

1 string reference to 'addanother_node_form_submit'
addanother_form_node_form_alter in ./addanother.module
Implements hook_form_BASE_FORM_ID_form_alter().

File

./addanother.module, line 130
Allows users to Add Another node of the same type easily.

Code

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

  /* @var \Drupal\node\NodeInterface $node  */
  if ($node = $form_state
    ->getFormObject()
    ->getEntity()) {
    $type = $node
      ->getType();
    $form_state
      ->setRedirect('node.add', [
      'node_type' => $type,
    ]);
    _addanother_quelch_message($node);
    \Drupal::messenger()
      ->addMessage(t('You may now create another.'));
  }
}