function save_edit_form_alter in Save & Edit 8
Same name and namespace in other branches
- 6 save_edit.module \save_edit_form_alter()
- 7 save_edit.module \save_edit_form_alter()
Implements hook_form_alter().
File
- ./
save_edit.module, line 31 - Contains save_edit.module..
Code
function save_edit_form_alter(&$form, FormStateInterface $form_state) {
$form_object = $form_state
->getFormObject();
$user = \Drupal::currentUser();
if ($user
->hasPermission('use save and edit') && $form_object instanceof NodeForm) {
$config = \Drupal::config('save_edit.settings');
$entity = $form_object
->getEntity();
$content_type = $entity
->getType();
$enabled_node_types = !is_null($config
->get('node_types')) ? $config
->get('node_types') : [];
if (in_array($content_type, array_values($enabled_node_types), TRUE)) {
$form['actions']['save_edit'] = [
'#type' => 'submit',
'#value' => $config
->get('button_value'),
'#name' => 'save_edit',
'#submit' => [
'::submitForm',
'save_edit_form_submit_presave',
'::save',
'save_edit_form_submit_redirect',
],
'#weight' => $config
->get('button_weight'),
];
if ($config
->get('dropbutton')) {
$form['actions']['save_edit']['#dropbutton'] = 'save';
}
if ($config
->get('hide_default_save')) {
$form['actions']['unpublish']['#access'] = FALSE;
$form['actions']['submit']['#access'] = FALSE;
}
if ($config
->get('hide_default_publish')) {
$form['actions']['publish']['#access'] = FALSE;
}
if ($config
->get('hide_default_preview')) {
$form['actions']['preview']['#access'] = FALSE;
}
if ($config
->get('hide_default_delete')) {
$form['actions']['delete']['#access'] = FALSE;
}
}
}
}