Steps

  • Fresh install of d7
  • Go to admin/content
  • Click update
  • Voila Errors
    *  Warning: array_filter(): The first argument should be an array in node_admin_nodes_submit() (line 493 of /var/www/example/modules/node/node.admin.inc).
    * Warning: Invalid argument supplied for foreach() in node_mass_update() (line 305 of /var/www/example/modules/node/node.admin.inc).

Comments

bleen’s picture

subscribe

bleen’s picture

Assigned: Unassigned » bleen
Status: Active » Needs review
StatusFileSize
new1013 bytes

This patch should do it ... please to review

redndahead’s picture

Status: Needs review » Reviewed & tested by the community

I can verify that this fixes this issue. It can be committed, but we'll need tests in that area.

jim0203’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.07 KB

Good work at fixing the problem, but I think it would be good if we gave the user some feedback rather than just dumping them back where they started.

I have, therefore, added a couple of lines to the patch which display a warning message that "No nodes were selected" and then returns - if the return line is removed then node_mass_update() is called, which itself displays a message saying that nodes have been updated - thus contradicting themessage I have added.

jim0203’s picture

StatusFileSize
new1.08 KB

Sorry, the tabs weren't right in that code. Fixed here.

bleen’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.08 KB

I confirm that jim0203's patch (a) works and (b) is more user friendly than the one I posted above...

The white space was a bit weird (this patch fixes it) ... but other than that, its good to go ...

bleen’s picture

Status: Needs review » Reviewed & tested by the community

forgot to change "status".

redndahead’s picture

Status: Needs review » Reviewed & tested by the community
+++ modules/node/node.admin.inc	22 Oct 2009 17:43:46 -0000
@@ -490,7 +490,11 @@ function node_admin_nodes_submit($form, 
+  $nodes = is_array($form_state['values']['nodes']) ? array_filter($form_state['values']['nodes']) : array();
+  if ($nodes == array()){
+    drupal_set_message('No nodes were selected.', 'warning');
+    return;
+  }

I think I would like to see it more like:

  if (!is_array($form_state['values']['nodes'])) {
    drupal_set_message('No nodes were selected.', 'warning');
    return;
  }
  $nodes = array_filter($form_state['values']['nodes']);

Seems a little cleaner to me.

This review is powered by Dreditor.

bleen’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.06 KB

@redndahead ... an excellent suggestion. see patch

redndahead’s picture

Status: Needs review » Needs work

sorry I'm not throwing up a patch, but documentation needs some work.

  // If no nodes are selected tell the user and return. 
  if (!is_array($form_state['values']['nodes'])) {
    drupal_set_message('No nodes were selected.', 'warning');
    return;
  }

  // Filter out unchecked nodes
  $nodes = array_filter($form_state['values']['nodes']);
jim0203’s picture

StatusFileSize
new1.15 KB

New patch, incorporating suggestions in #10

redndahead’s picture

Status: Needs work » Needs review
StatusFileSize
new1.15 KB

Minor Cleanup of white space and adding a period to the comment.

Status: Needs review » Needs work

The last submitted patch failed testing.

redndahead’s picture

Status: Needs work » Needs review
StatusFileSize
new914 bytes

Let's try this

redndahead’s picture

StatusFileSize
new912 bytes

Stupid white space again.

bleen’s picture

StatusFileSize
new1.13 KB

**IGNORE THIS** ... I hadn't refreshed the page and seen that someone else already submitted a patch that passed

bleen’s picture

Status: Needs review » Reviewed & tested by the community

I've tested "empty_update-609152-6.patch" and it works fine ... I think we are ready to go.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Minor nit-pick. We don't say "node" anywhere in user-facing text. It should be 'content' instead. Feel free to mark back to RTBC when this is fixed.

redndahead’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new916 bytes

There ya go

webchick’s picture

Status: Reviewed & tested by the community » Needs work
+++ modules/node/node.admin.inc	24 Oct 2009 05:58:22 -0000
@@ -489,6 +489,13 @@ function node_admin_nodes_validate($form
   $operations = module_invoke_all('node_operations');
   $operation = $operations[$form_state['values']['operation']];
+  
+  // If no content is selected tell the user and return.
+  if (!is_array($form_state['values']['nodes'])) {
+    drupal_set_message('No content was selected.', 'warning');
+    return;
+  }
+

Hmmm. And now that I look at this again, let's actually move this new logic up to the very top of the function. There's no point in invoking node_operations hooks if they didn't select any content.

This review is powered by Dreditor.

redndahead’s picture

Assigned: bleen » Unassigned
Status: Needs work » Reviewed & tested by the community
StatusFileSize
new874 bytes

Seek and ye shall find.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Hm. And in looking at this /again/ there's something else funny going on here.

a) We should not be doing checks like this in a submit handler. Submit handlers should be able to assume that everything's hunky-dory.

b) Where this kind of logic belongs is in the validate handler for a form.

c) However, there already /is/ a validate handler in the form, which is basically doing exactly this:

function node_admin_nodes_validate($form, &$form_state) {
  $nodes = array_filter($form_state['values']['nodes']);
  if (count($nodes) == 0) {
    form_set_error('', t('No items selected.'));
  }
}

So the real problem is figuring out why that code isn't firing.

redndahead’s picture

Title: Warnings when click Update on admin/content when there is no content. » node_admin_nodes_validate is never called when clicking update in admin/content

I can verify that node_admin_nodes_validate doesn't seem to get called. Also It seems the params in that function are wrong. It should be

function node_admin_nodes_validate($node, &$form)

If we could get it to call node_admin_nodes_validate it would balk at the array_filter() call. So once we can get node_admin_nodes_validate called we should move the last patch as the method used in that function.

redndahead’s picture

Ugh forget most of my last post. I am too tired to be making comments.

redndahead’s picture

Status: Needs work » Needs review
StatusFileSize
new955 bytes

Here is a fixed patch. The validate function was named wrong. Plus it needed to check to see if $form_state['values']['nodes'] is an array.

Status: Needs review » Needs work

The last submitted patch failed testing.

redndahead’s picture

Status: Needs work » Needs review
StatusFileSize
new1.26 KB

Needed to only validate if we click update.

webchick’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Update from IRC:

+++ modules/node/node.admin.inc	24 Oct 2009 17:42:00 -0000
@@ -474,10 +474,19 @@ function node_admin_nodes() {
+  if ($form_state['clicked_button']['#value'] == 'Update') {

The problem with code like this is that it doesn't work when my site is in French, and 'Update' becomes 'Réviser' or whatever.

While wrapping 'Update' in t() can mitigate that, this also breaks if a front-end developer decides to go in and form_alter() it to a different label altogether, not going through the translation system.

A better way to go would be to attach the validate handler to the button itself. I looked around in core briefly for an example and didn't find one, but basically it would entail:

[13:56]  <webchick> 1. Rename the function to something that won't auto-trigger when the form is submitted (like node_admin_nodes_update_validate)
[13:56]  <webchick> 2. In the definition of the submit button, add:
[13:57]  <webchick> '#validate' => 'node_admin_nodes_update_validate'
(or something like that)

Also, since this has to be the biggest disparity severity of problem : back-and-forth to fix it ratio I've seen on an issue in a long time, I think we officially need some tests for this so we don't ever break it again. :)

This review is powered by Dreditor.

redndahead’s picture

Status: Needs work » Needs review
StatusFileSize
new2.07 KB

Incorporated webchick's irc suggestions. And now with a new test.

redndahead’s picture

StatusFileSize
new2.07 KB

And of course white space.

webchick’s picture

Status: Needs review » Needs work

Ok! Last (hopefully) things to change. :) Great job on the perseverance here!

+++ modules/node/node.admin.inc	24 Oct 2009 18:38:44 -0000
@@ -475,6 +476,13 @@ function node_admin_nodes() {
+  // Error if there are no items to select.
+  if (!is_array($form_state['values']['nodes'])) {
+    form_set_error('', t('No items selected.'));
+    return;
+  }
+
+  // Error if there are no items selected.
   $nodes = array_filter($form_state['values']['nodes']);
   if (count($nodes) == 0) {
     form_set_error('', t('No items selected.'));

1. Let's condense these two things down to one check. In other words:

if (!is_array(..) || count(...) == 0) {
...
}

2. Don't return; here. We want all of the validation routines to fire. Errors are accumulated in form_set_error().

+++ modules/node/node.test	24 Oct 2009 18:38:45 -0000
@@ -967,6 +967,9 @@ class NodeAdminTestCase extends DrupalWe
+    $this->drupalPost('admin/content', array(), t('Update'));
+    $this->assertText(t('No items selected.'), t('Clicking update with no nodes displays error message on the node administration listing.'));

This is good, and checks for the situation where there are no nodes to select. We should also check for the condition where there ARE nodes but none are selected.

I'm on crack. Are you, too?

redndahead’s picture

Status: Needs work » Needs review
StatusFileSize
new2.47 KB

Here's the fixes.

redndahead’s picture

StatusFileSize
new2.55 KB

*grumble* white space *grumble*

webchick’s picture

Status: Needs review » Fixed

By jove, I think you've got it! :) I can officially find nothing else to complain about now, so committed to HEAD!

Great work! :D

redndahead’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Needs review
StatusFileSize
new693 bytes

Here is a d6 patch. It seems it passes an array ok in d6 so no need to check if it's an array.

redndahead’s picture

Behavior is different in d6.

1) Install fresh d6
2) go to admin/content
3) click update
It should say it was updated successfully. It should say that no items were selected.

bleen’s picture

#35 works in Drupal 6.15

dpearcefl’s picture

Priority: Critical » Normal
Status: Needs review » Postponed (maintainer needs more info)

Has this been fixed in the latest D6?

bleen’s picture

Status: Postponed (maintainer needs more info) » Needs review

nope

dpearcefl’s picture

If #35 works with D6, can you please post a copy of the patch under 6.x-dev?

bleen’s picture

StatusFileSize
new424 bytes

rerolled #35 using git

dpearcefl’s picture

Status: Needs review » Needs work

Sorry bleen18, your patch was ignored because of the filename I think. Try this format:

[description]-[issue-number]-[comment-number].patch

from http://drupal.org/node/1054616

Try resubmitting the patch and changing the status back to "needs review".

bleen’s picture

Status: Needs work » Needs review
StatusFileSize
new424 bytes
redndahead’s picture

Issue tags: -Needs tests

D6 patches don't go through the testing. That's why it was ignored.

redndahead’s picture

By the way the patch looks good as far as the git version matching the cvs version. Since it's still somewhat my own patch I can't RTBC. Can someone else look at this to RTBC?

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.