如何增强Drupal 8 Views批量操作确认页面?

时间:2018-10-14 07:46:59

标签: drupal-8 drupal-views bulk-operations

对于自定义的Views Views Bulk Operations操作,我想增强确认页面上列表中的信息,例如,代替:

  • 姓氏1
  • 姓氏2

我想要:

  • 姓氏1,名字,前缀
  • 姓氏2,名字,前缀

更改此设置的最佳位置在哪里?

1 个答案:

答案 0 :(得分:1)

Drupal 8中基本上有两种方法可以做到这一点:

  1. 使用hook_form_views_bulk_operations_confirm_action_alter。这将允许您更改列表,例如使用自定义值和代码。
  2. 如果定义了自定义操作插件,则可以在插件注释中将路由名称声明为自定义验证表单。这将允许您做任何您想做的事情,包括多步骤表单。定义该自定义表单时,您应该将Drupal \ views_bulk_operations \ Form \ ConfirmAction子类化,因为它的buildForm方法采用的参数不同于常规表单的参数。因此,您的插件将像这样开始:
/**
* 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 {
}

,表单将如下所示:

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) {
    ....
  }

在自定义表单类中,如果要向自定义操作传递特殊的内容,则必须定义自己的SubmitForm方法。