How can VBO be used to change the commenting status (disabled, read only, read/write) of nodes? Am I overlooking someone very simple?

Comments

infojunkie’s picture

There is currently no action that lets you change the commenting status. You can contribute it or mark this issue as a feature request.

infojunkie’s picture

Status: Active » Fixed

Here's a recipe to achieve this:
* In Administer > Site configuration > Actions, create a new advanced action of type "Execute arbitrary PHP script".
* In the "PHP script" section, type:

$object->comment = COMMENT_NODE_READ_WRITE;
node_save($object);

* Save the new action under a descriptive name.
* In your VBO admin page, select the new action in the style settings.
* Save the updated VBO and navigate to its page.
* Select a few nodes and apply the new action to them.

Note that you can choose to disable comments (COMMENT_NODE_DISABLED), make them read-only (COMMENT_NODE_READ_ONLY) or read-write (COMMENT_NODE_READ_WRITE).

Hope this helps!

Status: Fixed » Closed (fixed)

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

JamieR’s picture

That was awesome. Thank you.

michelle’s picture

Version: 6.x-1.8 » 6.x-1.x-dev
Category: support » feature
Status: Closed (fixed) » Active

It's great that there's a recipe for this but I'm wondering if there's some reason it can't be included with VBO to begin with? This seems like a pretty common operation.

Thanks,

Michelle

infojunkie’s picture

Component: Documentation » Actions
Status: Active » Postponed

I'd be grateful if someone could package this recipe as a configurable action, allowing to choose which commenting option to apply.

gpk’s picture

#2 works well, many thanks.

bisuteria’s picture

Thank you very much Mr. Karim Ratib
I will save many hours of work.

shopdogg’s picture

+1 for this feature.

hixster’s picture

Subscribe

chrisdbarnett’s picture

This really should be included as a standard action in Drupal.

It's not nice to wade through bad code examples to eventually find the right one.

Hat tip to info Junkie for the working code example.

Anonymous’s picture

Awesome! Thanks Todd Nienkerk for asking and Infojunkie for the great resolution!

infojunkie’s picture

Category: feature » support
Status: Postponed » Fixed
infojunkie’s picture

Category: support » feature
Status: Fixed » Postponed

Sorry, wrong move :-)

tammo’s picture

Great, thank you very much. Saved me an evening of work...

Vote_Sizing_Steve’s picture

#2 works well, but I'm still casting a vote for #6.

todd nienkerk’s picture

Version: 6.x-1.x-dev » 6.x-3.x-dev
Assigned: Unassigned » todd nienkerk
Status: Postponed » Needs review
StatusFileSize
new1.39 KB

The attached patch introduces an action to change the comment setting on a node. I left a stub validation function in case it's necessary for reasons I don't understand.

todd nienkerk’s picture

Version: 6.x-3.x-dev » 6.x-1.x-dev

Accidentally checked out the 6.x-3.x branch. I tested the patch against 6.x-1.x, and it works.

todd nienkerk’s picture

Re-rolled to work with 6.x-1.x branch. (Turns out this branch lists each of the actions files instead of parsing the folder.)

alexmoreno’s picture

do you know if does not work with nodecomment???

alexmoreno’s picture

for anyone interested, possible solution (via sql hacking):

http://drupal.org/node/164393#comment-4403834

edbradburn’s picture

Version: 6.x-1.x-dev » 7.x-3.0-beta3

I have just set this up using Views Bulk Operations and Rules.

For information on how to link VBO with Rules, there is an excellent video from Nodeone.se: http://dev.nodeone.se/en/blog/nodeone-talks-drupal-rules-vbo-revisited#c....

Basically, you set up a rule set (it's a Component, not a "normal" Rule) with the required action and then add a new View with a VBO field to enable the action to be performed.

It took me all of 5 minutes, the two tools really are very powerful indeed.

The rule action by the way is "Set a data value" and the target is the data item "[node-comments:comment]". The value of this data item gets set to either 0, 1 or 2 depending on whether you want no comments, comments, or read-only comments (in that order).

If you need any help, mail me. I'm a Drupal newbie (although I have a background in IT, PHP and databases) but I seem to have worked this out so far (I'm still stunned how far Drupal has come in the five years I have been away from it).

bojanz’s picture

Version: 7.x-3.0-beta3 » 6.x-1.x-dev

Changing back to 6.x-1.x since there's a patch that might be considered for that branch.

Thanks for the tip, edbradburn!

jjbell’s picture

#2 looks like it will accomplish what I am trying to do but "Execute arbitrary PHP script" does not appear in the drop down menu at "Administer > Site configuration > Actions" in Drupal 7. Any ideas?
I have enabled PHP filter (which I assume is needed) and also checked permissions.

bojanz’s picture

The VBO for D7 can do this out of the box with tomorrow's -dev, using the "Modify entity values" action.

goron’s picture

Status: Needs review » Needs work

The patch from #19 for 6.x-1.x works for me. However, it's missing comment blocks for all of the functions, and includes a commented out function. Needs coding standards work.

goron’s picture

Actually it seems that the 1.x branch now doesn't list the available actions in a file, but detects them automatically, so the patch in #17 is the one to use for the 1.x branch.

Coding standards issues still apply.

goron’s picture

StatusFileSize
new1.41 KB

Sorry, one more change. The action files are now located in the actions folder. So slight change to the patch. This one will apply cleanly to 1.x-dev and place the new action in the right location.

Encarte’s picture

Status: Needs work » Needs review
infojunkie’s picture

Status: Needs review » Fixed

Committed to latest dev with slight changes.

Note to action authors: On the action form, don't forget to read the default values from the $context array. This is essential in two cases:
* If a validation error occurs on the form, values are not lost when the form is re-displayed.
* If the user saves your action with preset arguments (in the "Advanced actions" section of admin/settings/actions/manage), preset arguments are automatically used in the VBO (or anywhere that the saved action is used.)

infojunkie’s picture

Version: 6.x-1.x-dev » 7.x-3.x-dev
Status: Fixed » Patch (to be ported)

Any interest for D7?

bojanz’s picture

Version: 7.x-3.x-dev » 6.x-1.x-dev
Status: Patch (to be ported) » Fixed

See #25. This is possible in D7 with the "Modify entity values" action (included since RC1).
I think that's enough (plus, Rules can be used as well, if the user just hates that action).

Status: Fixed » Closed (fixed)

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

MakeOnlineShop’s picture

Hello,

I couldn't manage to use VBO to disable comments on some nodes, cam you help me more ?

Thanks.