Today I had a bunch of old nodes from a migrated d6 site that did not have comments enabled, although the content type had comments enabled. This could also be the case if you have created a bunch of nodes, and all of sudden change your mind and want to enable comments on them anyway. One could always edit each one of them and turn on the comments, but that just can't be the only way, I thought, and did some research.

At first I didn't find any out-of-the-box way to enable comments for multiple nodes. Programatically enabling comments for all nodes by looping through nodes and enabling comments in a simple script could always be done, but my solution was even simpler. I used the module Views bulk operations. The easiest way was if VBO had an action already created for enabling comments, but as that wasn’t the case, it is really not a long snippet to execute on each row. Here is the steps I used to achieve what I wanted.

  1. Downloaded and enabled views bulk operations
  2. Created a view displaying all nodes of the content type I wanted to enable comments on
  3. Added a VBO field
  4. Enabled the Execute PHP action for this field, and also the “select all nodes” checkbox
  5. Added a page display
  6. Viewed the view page, selected all nodes and executed the PHP action.
  7. Entered the following snippet as action
$entity->comment = 2;
node_save($entity);

Done!