Problem/Motivation

1. create a node.
2. open /admin/content on 2 browser tabs.
3. on the 1st tab delete the created node.
4. on the 2nd tab select the node created in step 1.
5. select the "Delete content" action.
6. click the "appy to selected items"

Now, there is an warning message:

Warning: array_filter() expects parameter 1 to be array, null given in Drupal\views\Plugin\views\field\BulkForm->viewsFormValidate() (line 464 of core/modules/views/src/Plugin/views/field/BulkForm.php).

Proposed resolution

Don't show this error.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kaszarobert created an issue. See original summary.

kaszarobert’s picture

Version: 8.6.7 » 8.8.x-dev
Priority: Normal » Minor

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

nisha_gupta’s picture

Version: 8.9.x-dev » 8.8.x-dev
Component: node system » views.module
Status: Active » Needs review
FileSize
1000 bytes

This patch works for me. Need review

Lendude’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
  1. +++ b/core/modules/views/src/Plugin/views/field/BulkForm.php
    @@ -406,7 +406,11 @@ public function viewsFormSubmit(&$form, FormStateInterface $form_state) {
    +          \Drupal::messenger()->addError("node cannot be deleted because it doesn't exist");
    

    This should use $this->messager

  2. +++ b/core/modules/views/src/Plugin/views/field/BulkForm.php
    @@ -406,7 +406,11 @@ public function viewsFormSubmit(&$form, FormStateInterface $form_state) {
    +          return $this->getDestinationArray();
    

    The early return would mean all the entities are not deleted, shouldn't we just skip the one we can't delete?

  3. +++ b/core/modules/views/src/Plugin/views/field/BulkForm.php
    @@ -406,7 +406,11 @@ public function viewsFormSubmit(&$form, FormStateInterface $form_state) {
    +        } ¶
    

    trailing whitespace

Also, this needs a test

ravi.shankar’s picture

Status: Needs work » Needs review
FileSize
977 bytes

Here I have tried to address comment #5.

emyu01’s picture

Status: Needs review » Needs work

Hi, this is the error I got while trying to replicate

Warning: array_filter() expects parameter 1 to be array, null given in Drupal\views\Plugin\views\field\BulkForm->viewsFormValidate() (line 464 of core/modules/views/src/Plugin/views/field/BulkForm.php).
Drupal\views\Plugin\views\field\BulkForm->viewsFormValidate(Array, Object) (Line: 162)
Drupal\views\Form\ViewsFormMainForm->validateForm(Array, Object) (Line: 179)
Drupal\views\Form\ViewsForm->validateForm(Array, Object)
call_user_func_array(Array, Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 275)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'views_form_content_page_1') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('views_form_content_page_1', Array, Object) (Line: 577)
Drupal\Core\Form\FormBuilder->processForm('views_form_content_page_1', Array, Object) (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 218)
Drupal\Core\Form\FormBuilder->getForm(Object, Object, Array) (Line: 2242)
Drupal\views\Plugin\views\display\DisplayPluginBase->elementPreRender(Array)
call_user_func_array(Array, Array) (Line: 100)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725', 'silenced_deprecation', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 444)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
No content selected.

The patch 3030989-6.patch also did not have any effect on the error displayed.

Lendude’s picture

Priority: Minor » Normal
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
1 KB
1.74 KB

I also see the error in #7, this is also what an automated test for this shows. Updated the IS to reflect the new error.

Here is a test and a new fix for this. No interdiff because this is a whole new approach.

The last submitted patch, 8: 3030989-8-TEST-ONLY.patch, failed testing. View results

emyu01’s picture

Status: Needs review » Reviewed & tested by the community

Patch applied cleanly and works as expected.

catch’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/views/tests/src/Functional/BulkFormTest.php
@@ -157,6 +157,20 @@ public function testBulkForm() {
+    $this->drupalGet('test_bulk_form');
+    // Now delete the node we want to delete with the bulk form.
+    foreach ($nodes as $node) {
+      $node->delete();
+    }
+    $edit = [

It looks like we don't have coverage for the case where multiple nodes are selected, and only one is deleted?

emyu01’s picture

hello @catch,

Attached is an updated patch including interdiff fixing error when multiple nodes selected but one or more but not all are already deleted. Also fixed error when multiple nodes selected and all have already been deleted. Tests to cover both cases have been added too.

Status: Needs review » Needs work

The last submitted patch, 12: 3030989-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

emyu01’s picture

Assigned: Unassigned » emyu01
emyu01’s picture

Assigned: emyu01 » Unassigned
Status: Needs work » Needs review
FileSize
2.85 KB
3.84 KB

Patch is re-attached for review.

Status: Needs review » Needs work

The last submitted patch, 15: 3030989-13.patch, failed testing. View results

Lendude’s picture

Status: Needs work » Needs review
FileSize
3.96 KB
4.3 KB

Thanks @emyu01, this fixes the new tests. The error only occurs when all nodes have been deleted. The current behaviour is that when you select one node and that node doesn't exist (but there are still other nodes), you get returned to the bulk form page without any messages.

Not sure if that is the best behaviour, but it is better than a warning.

emyu01’s picture

Great! thanks @Lendude.

emyu01’s picture

Status: Needs review » Reviewed & tested by the community

Patch tested and looks all good.

  • catch committed c266bb6 on 9.1.x
    Issue #3030989 by Lendude, emyu01, ravi.shankar, nisha_gupta,...

  • catch committed 648d7aa on 8.9.x
    Issue #3030989 by Lendude, emyu01, ravi.shankar, nisha_gupta,...

  • catch committed f3004da on 8.8.x
    Issue #3030989 by Lendude, emyu01, ravi.shankar, nisha_gupta,...

  • catch committed 0a97ae8 on 9.0.x
    Issue #3030989 by Lendude, emyu01, ravi.shankar, nisha_gupta,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed c266bb6 and pushed to 9.1.x, and cherry-picked back to 8.8.x. Thanks!

Status: Fixed » Closed (fixed)

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