Adjust VBO text labels and set button weightings

Public

Adjust VBO text labels and set button weightings. Taken from https://drupal.org/node/1550092

Get raw version
php
  1. **
  2. * Implements hook_module_implements_alter
  3. * Ensures our form_alter runs after VBO
  4. */
  5. function EXAMPLE_module_implements_alter(&$implementations, $hook) {
  6. if ($hook == 'form_alter') {
  7. if(isset($implementations['EXAMPLE'])){
  8. $group = $implementations['EXAMPLE'];
  9. unset($implementations['EXAMPLE']);
  10. $implementations['EXAMPLE'] = $group;
  11. }
  12. }
  13. }
  14.  
  15. /**
  16.  * Implements hook_form_FORM_ID_alter().
  17.  */
  18. function EXAMPLE_form_views_form_alter(&$form, &$form_state, $form_id) {
  19. // Adjust VBO text labels and set button weightings
  20. // Set button order with #weight
  21. if (isset($form['select']) && $form['select']['#title'] == 'Operations') {
  22. // Adjust text
  23. $form['select']['#title'] = t('Update');
  24. $form['select']['submit']['#value'] = t('Update');
  25. if (isset($form['select']['operation']['#options'])) {
  26. $form['select']['operation']['#options'][0] = t('Choose an update option');
  27. }
  28. // Adjust button weightings
  29. // Publish node
  30. if (isset($form['select']['action::node_publish_action'])) {
  31. $form['select']['action::node_publish_action']['#weight'] = -20;
  32. }
  33. // Unpublish node
  34. if (isset($form['select']['action::node_unpublish_action'])) {
  35. $form['select']['action::node_unpublish_action']['#weight'] = -18;
  36. }
  37. // Modify entity values
  38. if (isset($form['select']['action::views_bulk_operations_modify_action'])) {
  39. $form['select']['action::views_bulk_operations_modify_action']['#weight'] = -8;
  40. }
  41. // Save node
  42. if (isset($form['select']['action::node_save_action'])) {
  43. $form['select']['action::node_save_action']['#weight'] = -6;
  44. }
  45. // Delete item
  46. if (isset($form['select']['action::views_bulk_operations_delete_item'])) {
  47. $form['select']['action::views_bulk_operations_delete_item']['#weight'] = 10;
  48. }
  49. }
  50. }