Problem/Motivation

The generic ActionBulkForm provides a mostly unnecessary field handler that is redundant with the more specific bulk handlers provided by Node and User module. This results in a confusing option for end users who don't know if they should choose "Action: Bulk update" or "User: Bulk update".

Bulk actions choices

The arrangement of ActionBulkForm is also confusing for developers, as the class itself is provided by Views in \Drupal\views\Plugin\views\field\BulkForm however it is exposed to the end-users by Action module in action_views_data(). It would be less confusing for developers if the class and the exposure to Views were both owned by the same module, rather than one module directly using another's field handler.

Proposed resolution

Move the functionality from the ActionBulkForm to the BulkFormBase class and remove ActionBulkForm from action_views_data() (actually the whole function/file can be removed, since this is the only handler exposed by Action module).

User interface changes

The "Action: Bulk update" would no longer be available in the Views interface.

API changes

Modules wishing to use bulk operations will need to extend BulkFormBase for each entity needing to be supported.

#1851082: Add a base bulk form handler class
#1851086: Replace admin/people with a View
#1895160: Convert admin/content to a View, keep a non-views fallback with no bulk operations

Comments

pcambra’s picture

StatusFileSize
new9.65 KB

Here's a first take, probably we'll get some test errors due to #2049569: Delete multiple for nodes is broken

pcambra’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2049573-bulkformbase-1.patch, failed testing.

pcambra’s picture

Status: Needs work » Needs review
StatusFileSize
new10.36 KB
new729 bytes
dawehner’s picture

+++ b/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkFormBase.php
@@ -73,6 +73,52 @@ public function preRender(&$values) {
+   * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::defineOptions().
...
+   * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::buildOptionsForm().
...
+   * Overrides \Drupal\views\Plugin\views\HandlerBase::validateOptionsForm().

Let's use @inheritdoc here.

+++ b/core/modules/user/lib/Drupal/user/Tests/Views/BulkFormTest.php
@@ -42,7 +42,7 @@ public function testBulkForm() {
-    $this->assertText(t('No users selected.'));
+    $this->assertText(t('No items selected.'));

I am wondering whether the string should be overridden for users.

pcambra’s picture

StatusFileSize
new10.14 KB
new3.61 KB

Let's see how this looks like.

dawehner’s picture

+++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/NodeBulkForm.php
index f7c5ea2..08b85b8 100644
--- a/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkFormBase.php

--- a/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkFormBase.php
+++ b/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkFormBase.php

I am not sure whether we talked about that already, but I would like to move this to views out of system. (I am not sure whether you consider this out of scope here).

pcambra’s picture

dawehner’s picture

That is perfect now.

@@ -165,6 +235,35 @@ public function views_form_submit(&$form, &$form_state) {
+   * Set a message text to be displayed when there are no items selected in the
+   * listing.

Can't you make some changes to get it to a one-liner, forget a word or something like that :p

longwave’s picture

How about "Returns the message to be displayed when there are no selected items."?

pcambra’s picture

pcambra’s picture

StatusFileSize
new10.15 KB

Here's a rebase after #11 that replaces the comment by @longwave suggestion on #10

dawehner’s picture

@@ -165,6 +235,34 @@ public function views_form_submit(&$form, &$form_state) {
+   * @return string

Even the @return need a description :(

pcambra’s picture

StatusFileSize
new10.2 KB
new678 bytes

Here we go!

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Added an issue summary, so I can RTBC it!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

So at the moment this patch does do much because #2020979: Bulk action form no longer allows actions to be selected changed class NodeBulkForm extends ActionBulkForm { :)

The question now becomes should we do this? If so should NodeBulkForm extend BulkFormBase again?

pcambra’s picture

The question now becomes should we do this? If so should NodeBulkForm extend BulkFormBase again?

I wonder the exact same thing, the initial purpose of this was to make the action selection form available without the action module to be enabled, so I don't know if this is wanted still or not.

pcambra’s picture

Issue summary: View changes

Added issue summary.

quicksketch’s picture

Title: Move most of the bulkForm class to bulkFormBase » Move most or all of the ActionBulkForm class to BulkFormBase
Issue summary: View changes
StatusFileSize
new55.34 KB

The situation in core has changed a bit since this was filed. Since ActionBulkForm (previously known as BulkForm) is now extended by Node and User modules, we have a new problem that could be resolved with this same solution, so I updated the issue summary to focus on this problem. Out-of-the-box, currently there are *two* options for bulk operations for both nodes and users, one called "Action: Bulk update" and the other called "Content: Bulk update" (or "User: Bulk update"). From the appearance of things, the *only* difference between these is the validation errors are more specific on the Content/User variants.

From an end-user perspective, having two nearly identical fields for the most common data types adds unneeded confusion. If we continue with the solution proposed here of moving/merging BulkForm into BulkFormBase, we could remove BulkForm entirely from hook_views_data() and cut the dependency tree down one level. This would have the effect of requiring other entity types to provide their own classes that extend BulkFormBase like User and Node have done, but I would think that would be a good thing considering some entity types (i.e. Taxonomy terms) don't have any available actions at all (though that may change after #1839516: Introduce entity operation providers, I believe).

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new22.03 KB

This rerolls the last patch as well as adds on action bulk form per entity type. Additional node/user alters the entry in order to set its own plugin ID.

damiankloip’s picture

StatusFileSize
new23.73 KB
new4.83 KB

Generally this is looking like a pretty sensible idea. However, can we also do this? and remove the need for basically the same code (in different places) for BulkFormBase and (User/Node bulk forms)?

It would be nice if we didn't need the User and Node bulk forms too, as it's alters, and field handlers - whilst not accomplishing too much.

Just to defend the current state of things (prior to this patch); all of this stuff was written when actions were still just a part of the action module. So I guess now some of it does look a bit crazy :)

tim.plunkett’s picture

Sure that works. Though why inject the whole entity manager and not the action storage?

damiankloip’s picture

StatusFileSize
new23.83 KB
new2.74 KB

Why not indeed.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Looks great!

The last submitted patch, 20: 2049573-20.patch, failed testing.

The last submitted patch, 22: 2049573-22.patch, failed testing.

tim.plunkett’s picture

Assigned: pcambra » Unassigned
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new8.54 KB
new31.35 KB

Updated the unit tests.

damiankloip’s picture

Status: Needs review » Reviewed & tested by the community

Great, thanks! Sorry for adding that init() method :p

dawehner’s picture

Thank you for updating the unit test!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

How come we've not removed ActionBulkForm? I can't find an usages.

damiankloip’s picture

Status: Needs work » Reviewed & tested by the community

ActionBulkForm is used to generate a bulk action field for all entity types. See views.views.inc

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
class ActionBulkForm extends BulkFormBase {

}

abstract class BulkFormBase extends FieldPluginBase {
// All the methods...
}

Well ActionBulkForm is an empty class so BulkFormBase is not very abstract then :)

Can't we remove ActionBulkForm and make BulkFormBase concrete and use it in views_views_data() instead of ActionBulkForm?

damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new32.24 KB
new1.94 KB

Here we go. removed ActionBulkForm and renamed BulkFormBase to BulkForm. How about that?

alexpott’s picture

works for me

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

It works for alex and me

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll
error: patch failed: core/modules/action/tests/action_bulk_test/config/views.view.test_bulk_form.yml:35
error: core/modules/action/tests/action_bulk_test/config/views.view.test_bulk_form.yml: patch does not apply
damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new32.25 KB

Here's a reroll.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs reroll

and back.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed dd4890b and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.