0

For a custom Views Views Bulk Operations action, I would like to enhance the information in the list on the confirm page, For example, instead of:

  • LastName1
  • LastName2

I would like to have:

  • LastName1, FirstName, Prefix
  • LastName2, FirstName, Prefix

Where is the best place to alter this?

jmux
  • 184
  • 4
  • 17

1 Answers1

3

There are basically two ways to do this in Drupal 8:

  1. using hook_form_views_bulk_operations_confirm_action_alter. This will allow you to alter the list, for example with custom values and code.
  2. If you have defined a custom action plugin, then in the plugin annotiation you can declare the route name to a custom validation form. This will allow you to do anything you want, including multi-step forms. When you define that custom form, you should subclass Drupal\views_bulk_operations\Form\ConfirmAction, since it's buildForm method takes parameters additional to that of a regular form. So your Plugin would start like this:
/**
* Action description.
*
* @Action(
*   id = "my_special_action",
*   label = @Translation("My Special Action"),
*   type = "custom_entity",
*   confirm_form_route_name = "my_module.my_special_action_confirm_form",
* )
*/
class MySpecialAction extends ViewsBulkOperationsActionBase {
}

and the Form will look something like this:

use Drupal\views_bulk_operations\Form\ConfirmAction;

class MySpecialActionConfirmForm extends ConfirmAction {

  public function getFormId() {
    return 'my_special_action_confirm_form';
  }


  public function buildForm(array $form, FormStateInterface $form_state, $view_id = NULL, $display_id = NULL) {
    ....
  }

In the custom form class, you will have to define your own submitForm method, if you want to pass anything special to the custom action.

jmux
  • 184
  • 4
  • 17