I'm developing a website where users access the content without registration but it still needs to have a favorites system for the elements on the web. Right now I have implemented a system where i can add items to a "favorites" and the node id for every item is saved on a cookie. Is there a way to filter the items that are shown by a view page using this node ids saved on the cookies?

I thought that it can be done by altering the query sent by the view or by aplying a filter in some point of the process where i check whether the element returned by the view corresponds with the node id saved in the cookie.

Is any of this options feasible? Is there a simpler way to focus this problem?

  • Check Drupal Setting Views Filter via Cookie for a quick solution. Alternatively (and better) look at Views hooks for a hook to implement where you add/alter the filter by reading the value from the cookie Jan 20, 2016 at 12:15
  • I could achieve it with the 'quick' solution method. It also open the door to solve my other problems without need to apply any hook. Thank you very much. Jan 20, 2016 at 14:33

1 Answer 1


A better way to tackle your problem might be the Flag module.

It also has a good views integration and is quite easy to set up.

Just add a "favorites" flag and set it as private flag, so every user can have its own favorites.

On your favorites-view set your filter criteria to match the flag and you are good to go.

  • This could work for implementing a "favorites" system but for what I've seen it works on users or roles. Since the website does not require registration i think it can not solve this problem. Anyway, the system to filter the results of views using data external to Drupal could be very useful for other implementations that i may need. Jan 20, 2016 at 9:54
  • It works for anonymous users as well since version 2.x.
    – Linus
    Jan 20, 2016 at 9:57
  • It solves my specific problem for the favorites system but I still need to know how to alter the results of a view using information not stored in drupal itself. In this case I've got the information in the cookies but it can also come from a query to a third party. Jan 20, 2016 at 10:23
  • You can use a contextual filter in your view and set the "provide default value" as described here drupal.org/node/1507522 to access your session variable. But I don't know what you mean by information from a third party query...
    – Linus
    Jan 20, 2016 at 10:32
  • 1
    You might need to code your own custom views filter or use hook_views_query_alter to modify the query. But this is quite far off from your original question.
    – Linus
    Jan 20, 2016 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.