Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi
I've been trying to add a feature to suppress notifications when updating nodes using VBO - in the same style as the content-admin page.
I've been able to add the logic, re-using the existing code, but it fails because VBO uses Drupal Actions, whereas content-admin calls update functions directly. I don't see any way around this.
I don't entirely understand how Actions work, but it seems that the actions run in a separate process, making it almost impossible to pass an additional flag from the UI into the actions.
Can anyone see a way of doing this?
Thanks
Comment | File | Size | Author |
---|---|---|---|
#6 | interdiff-4-6.txt | 2.33 KB | salvis |
#6 | subscriptions-suppress_in_vbo-2863216-6.patch | 3.66 KB | salvis |
#4 | subscriptions-suppress_in_vbo-2863216-4.patch | 3.22 KB | RickJ |
|
Comments
Comment #2
RickJ CreditAttribution: RickJ commentedI've figured this out, the key is to use a session variable. It's important to ensure the variable in only ever set transiently, because if left set then it could block subscriptions being sent for normal updates. I've attached a patch which is working for me.
The UI copies the check-box added to the admin people page, and defaults to not send subscriptions (which will usually be what is wanted for bulk operations). The check-box also appears on the configuration and confirmation pages. The flag has to be passed through these pages anyway - I could have hidden the box but this way you get a chance to change your mind on subscriptions before the final submit.
This is proving a life-saver for me, I need to do a lot of bulk changes (all status stuff, not content) but I couldn't risk spamming users with spurious notifications.
Comment #3
salvisThank you, this is generally useful and not trivial, i.e. worthy to go in.
However, we should introduce the session variable only if we actually need it. It should be either
$_SESSION['subscriptions']['suppress'] = 1;
or untouched, i.e.empty($_SESSION['subscriptions']['suppress'])
, i.e.unset($_SESSION['subscriptions']['suppress']);
.Drupal coding conventions: Comments are full sentences: start with Capital and end with period. Also warp at 80.
(I may have more comments later.)
Here you set it to TRUE whether VBO is there or not, but you don't set it to FALSE if the VBO form is not displayed!
Comments must end with a period. Make it
* Provides a session flag to suppress notifications.
Trailing space.
Should be the same as in the function above.
Why?
This should be
return !empty(...);
Comment #4
RickJ CreditAttribution: RickJ commentedThanks for the comments. In response:
That's actually what the code does. See
subscriptions_content_suppress_notifications_session()
.Because AFAIK you can't implicitly create multiple levels of array in a single []-style statement. And if the 'subscriptions' array didn't exist the last line in the function would throw an error. The array might already exist, having been created by other code in the module (e.g. the other VBO patch).
Agreed, that's more succinct.
On reflection, re-using the existing submit function for the admin-content page, and using both static and session flags at the same time, was not a good idea and left a hole in the logic. I've therefore changed it to use a separate function, and now only the session flag is used for VBO. The logic otherwise corresponds to the static flag, except that the session flag has to be explicitly cleared, which happens unconditionally in the VBO-form-alter hook. The VBO form is always the next page following the submit action, so the session flag should never be left set inadvertently.
I've tidied the comments, revised patch attached.
Comment #5
salvisSetting multiple indices is not a problem (as long as $_SESSION['subscriptions'] is not something other than an array), and empty() is more robust than you think.
No, you're always creating the empty array (if it doesn't exist), and you're not cleaning it up. To do what we want requires something like
I believe we should keep the
'When publishing unpublished nodes, this should probably be turned ON.'
note from the standard bulk implementation. If you fail to do this, you have a problem.There's still a bug in the logic. If I publish a node via ChangeValue|Status (with Send turned on), notifications aren't queued.
Some more minor Coding Standards stuff:
Wrap at 80.
Wrap at 80.
There is not concept of "above" in API documentation. Each docblock must stand on its own.
Still a trailing space here.
Comment #6
salvisI'm sorry, I've lost track of this.
Here's a minor increment. However, I think that
is still an open issue.
Comment #7
salvis