Skip to content

Instantly share code, notes, and snippets.

@anthonysimone
Created December 8, 2016 23:20
Show Gist options
  • Select an option

  • Save anthonysimone/b3e0ed9048826211046952e92150b2d2 to your computer and use it in GitHub Desktop.

Select an option

Save anthonysimone/b3e0ed9048826211046952e92150b2d2 to your computer and use it in GitHub Desktop.
Add a default `null` selection to the bulk actions dropdown on the main content page so `delete` is not the default action.
/**
* Implements hook_form_FORM_ID_alter().
*
* Specifically get the view content page form, look for the bulk field in the header, and add a non-item as default
*/
function HOOK_form_views_form_content_page_1_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
if (isset($form['header']['node_bulk_form']['action']['#type']) && $form['header']['node_bulk_form']['action']['#type'] === 'select') {
$form['header']['node_bulk_form']['action']['#options'] = array('' => '- Select Action -') + $form['header']['node_bulk_form']['action']['#options'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment