function addanother_form_node_type_form_alter in Add Another 8
Same name and namespace in other branches
- 7.2 addanother.module \addanother_form_node_type_form_alter()
Implements hook_form_BASE_FORM_form_alter().
File
- ./
addanother.module, line 27 - Allows users to Add Another node of the same type easily.
Code
function addanother_form_node_type_form_alter(&$form, FormStateInterface &$form_state, $form_id) {
$config = \Drupal::config('addanother.settings');
if ($node_type = $form_state
->getFormObject()
->getEntity()) {
$type = $node_type
->get('type');
// Get content type addanother settings.
$button = $config
->get('button.' . $type);
$message = $config
->get('message.' . $type);
$tab = $config
->get('tab.' . $type);
$tab_edit = $config
->get('tab_edit.' . $type);
$form['addanother_display'] = [
'#type' => 'details',
'#title' => t('Add another settings'),
'#collapsible' => TRUE,
'#group' => 'additional_settings',
];
$form['addanother_display']['button'] = [
'#type' => 'checkbox',
'#title' => t('Display Add another button on node add form.'),
'#default_value' => isset($button) ? $button : $config
->get('default_button'),
'#description' => t('Enable this checkbox if you want to provide a "Save and add another" button on the node add form for your users.'),
];
$form['addanother_display']['message'] = [
'#type' => 'checkbox',
'#title' => t('Display the Add another message after node creation.'),
'#default_value' => isset($message) ? $message : $config
->get('default_message'),
'#description' => t('Enable this checkbox if you want to show a "Add another..." message after creating a new node.'),
];
$form['addanother_display']['tab'] = [
'#type' => 'checkbox',
'#title' => t('Display the Add another tab.'),
'#default_value' => isset($tab) ? $tab : $config
->get('default_tab'),
'#description' => t('Enable this checkbox if you want to show a "Add another" tab on nodes of this type.'),
];
$form['addanother_display']['tab_edit'] = [
'#type' => 'checkbox',
'#title' => t('Also display Add another tab on edit page.'),
'#default_value' => isset($tab_edit) ? $tab_edit : $config
->get('default_tab_edit'),
'#description' => t('Enable this checkbox if you want to also show a "Add another" tab on node edit pages of this type. This option does nothing if the Add another tab is disabled.'),
];
$form['actions']['submit']['#submit'][] = 'addanother_form_node_type_form_submit';
}
}