I've googled this, tried different modules and plugins and patches and everything, and nothing seems to work or be compatible with 6.x.

I want a link (something like /markread) that will simply mark EVERYTHING as read on the site (all comments, all nodes which are published) and then return you to the previous page with a drupal message that says something like "You have cleared all "new" notifications." So far, nothing I've found on this site or third party sites has worked for me. Suggestions?

By the way, for anyone who is actively helping out with the development of 7.x: This NEEDS to be in Drupal 7.

-

Side note: Could this be done with views and/or the views "action" module (the one that puts checkboxes in a views table)? I have views installed and am using it, so I could do it that way if that's easier, I just don't know if there's an action for "Mark as read".

Comments

SpikeX’s picture

Nobody has any ideas? Really?

SpikeX’s picture

Okay, so I've been digging around the internet a bit, and it seems you can't do this with VBO (Views Bulk Operations), or the Actions module, or Drupal core.

If nobody knows how to do this, at the very least, does ANYONE know at what point nodes get "marked as read" or have their timestamps updated to reflect not-new status? I'd like to manually call the function that does this, within an action. I've tried node_load(), but that doesn't seem to update the timestamp for "read".

If ANYONE has any insight whatsoever, every little bit helps. Speak up!

WorldFallz’s picture

advanced forum has this capability for forum posts-- i would think you should be able to grab the code and alter as necessary for other content types.

michelle’s picture

If you want this in core for D7, helping with #515034: Mark all forum topics read is a good start.

Michelle

SpikeX’s picture

I actually managed to write an action that did this (using node_tag_new() or whatever it's called), and, using VBO, I have successfully implemented the feature I needed.

WorldFallz’s picture

Nice-- can you post the code for the action for future reference?

SpikeX’s picture

Post it where? I can't attach files to forum posts or replies.

WorldFallz’s picture

Not attach it-- just post (ie copy & paste) it, between <code> tags, right into the thread.

SpikeX’s picture

Sure, see below. :)

SpikeX’s picture

Place this code inside a module to get an action that will mark a node as "read". This works excellently with Views Bulk Operations.

/**
* Implementation of hook_action_info().
*/
function markread_action_info() {
  return array(
    'mark_read_node_action' => array(
      'description' => t('Mark as read'),
      'type' => 'node',
      'configurable' => FALSE,
      'hooks' => array('any' => TRUE),
      ),
  );
}

/**
* Callback for markread_action_info
*/
function mark_read_node_action($object, $context = array()) {
	if(isset($object->nid)) {
	    $nid = $object->nid;
	} else if(isset($context['nid'])) {
	    $nid = $context['nid'];
	}
	if(isset($nid)) {
		node_tag_new($nid);
	}
}

Note: Module name in this instance was "markread".

WorldFallz’s picture

Excellent-- thanks for posting! I'm sure other users will find this very useful.

caschbre’s picture

It's great to see someone come up with a solution. I know this topic has been hot in the forums for years now. :-)

Can you explain how you use this with VBO? Are you displaying all of your content to users with checkboxes? What are the use-cases for using this?

Also, I noticed the two functions have slightly different nomencature. One has markread_ and the other is mark_read_ ... is that correct?

SpikeX’s picture

Yes, that's correct. The callback function can be named whatever you like, but you can change it if you want. (Be sure to change it both places).

I personally use this on my site that has a "recent posts" page that displays a table of all new posts and forum topics and whatnot (including replies), and if I update, say, 10 different nodes, they all get marked as "Updated". My users can then simply "check" the ones they don't want to actually read and clear them using VBO. It's somewhat confusing, but it definitely has its place.

caschbre’s picture

Any interest in trying to make a custom module to handle various methods of marking nodes as read? Use the personal contact form and let me know if you'd be interested.

Cory Goodwin’s picture

I did as you posted. Now that the action is created how do we set off the action? Is there a way to create a menu item or themeable button?

jpshayes’s picture

SpikeX, thank you for the research and code you provided. I am trying to include this functionality in a site I am developing now. Hopefully I can come back and share my work and results here.

Melot’s picture

I did the above but nothing happened. Do you need to print the button in a .tpl.php-file? And how do you do that?

Azol’s picture

... read documentation for VBO concerning using Action API.
or just do this:

1) create markread.info file:

; $Id$
name = Mark Read
description = Mark node as read action.
core = 6.x

2) create markread.module file:

<?php
// $Id$

/**
* Display help and module information
* @param path which path of the site we're displaying help
* @param arg array that holds the current path as would be returned from arg() function
* @return help text for the path
*/

/**
* Implementation of hook_action_info().
*/
function markread_action_info() {
  return array(
    'mark_read_node_action' => array(
      'description' => t('Mark as read'),
      'type' => 'node',
      'configurable' => FALSE,
      'hooks' => array('any' => TRUE),
      ),
  );
}

/**
* Callback for markread_action_info
*/
function mark_read_node_action($object, $context = array()) {
    if(isset($object->nid)) {
        $nid = $object->nid;
    } else if(isset($context['nid'])) {
        $nid = $context['nid'];
    }
    if(isset($nid)) {
        node_tag_new($nid);
    }
}

3) put them both into your modules directory under 'markread' subdirectory.

4) enable the module

5) use the Mark Read action in VBO settings.

janis_lv’s picture

could this function mess up with other views, modules on the site?

Azol’s picture

It does not (at least on my site).
But it possibly could (who knows), that is what testing is about.

neRok’s picture

I was in need of the same feature for my Drupal 7 site. I have taken the code above and modified to suit. I have posted the module/code to the VBO issue queue under #1886916: Mark all nodes as read action.

SpikeX’s picture

Actually, for Drupal 7 it's really easy to achieve this, all you need to do is:

  • Create a new custom action with "Execute arbitrary PHP code".
  • Set the title to something like "Mark as read".
  • Set the code to be node_tag_new($entity);
  • In your VBO settings for your field in your view, set the action to "Mark as read" or whatever you called your action.

That's all there is to it. A custom action and one line of PHP.

Samlet9908’s picture

Great idea. I did it and it works well for the user executing the Mark as read action. Only thing is how to execute this for ALL users?