Home > 7 > How do I get a view of all flaggable nodes?

How do I get a view of all flaggable nodes?

December 26Hits:1
Advertisement

I have a custom flag defined only on certain content types and I want to make a convenient list of all nodes that the flag is being displayed on, that is, nodes of all the content types that the flag is defined on.

Answers

If these content types are never going to change, the quick and dirty would be to just create a View filtering on those content types.

If this is not the case, then you are going to have to get down into some coding as I am not aware of any built in Views/Flags integration on this level. Sure, you can list all flagged or not flagged content, but I don't see a way to list flaggable content.

So, to get the node types, you should be able to do something like this:

$flag=flag_get_flag('NAME_OF_THE_FLAG');

and now

$types=$flag->types;

should be an array of node types this flag can be applied to. So now you need to tell Views about this.

So, using the quick and dirty View created above, you could then alter it up with something along these lines:

function YOURMODULE_views_pre_view(&$view, &$display_id, &$args) {

  if ($view->name=='NAME_OF_THE_VIEW') {

    $flag=flag_get_flag('NAME_OF_THE_FLAG');

    $filters = $view->display_handler->get_option('filters');
    // you may want to dpm() or drupal_set_message() or watchdog() or otherwise look at $filter to see what you have to deal with on your system
    $filters['type']['value'] = $flag->types;

    $overrides = array();
    $overrides['filters'] = $filters;

    foreach ($overrides as $option => $definition) {
      $view->display_handler->override_option($option, $definition);
    }

  }

}

which on my box here, changes the types filtered to those in the flag.

Your $flag and $filters may/will most probably vary, so check to see what you have to work with as these are the broad strokes.

Lots of information about flags here: Flag 3.x PHP API

Information about Views hooks here: Views Hooks

Are you using a custom field or the Flag module?

In both cases, you should be able to create a view and then add filter either on your custom field or on your flag.

Tags:flags, nodes, views

Related Articles

  • How do I get a view of all flaggable nodes?December 26

    I have a custom flag defined only on certain content types and I want to make a convenient list of all nodes that the flag is being displayed on, that is, nodes of all the content types that the flag is defined on. --------------Solutions------------

  • Drupal View - list content of node in another viewJuly 27

    I have a View of some custom content type and want to link the name of each object in the view to another view containing its details. At the moment, I have the "link this field to its node" box checked but it doesn't display it in some sort of

  • Using a different view mode with a nodeAugust 29

    I understand using Views you can use a different view mode, e.g. teaser or full content. Is it possible to view a node using a view mode other than the full content view mode? What I want to achieve is being able to display different fields depending

  • Attach a view to a specific nodeDecember 12

    I'm looking for a module that makes it possible to attach an existing view to a specific node. I've looked at eva, but it seems only to allow connecting a view to all entities of a specific content-type. I wrote my own module, that can do this, and i

  • View cache clear on node createMay 24

    I've searched a lot of this but all kind of cache issues appear not related to this. If this has already been asked I apologize. I just want to know if this is an embedded feature or a module is needed for this. My homepage has 12 VIEW blocks with ve

  • List nodes with Views 2 module, despite nodes having restricted permissionsJune 20

    My nodes have individual Access Control permissions. I need anonymous users to be able to see a View (giving them a preview essentially) of these nodes, but currently they don't have access. Is there an easy way to override the permissions just for t

  • Default statistics module. Count views of only published nodes when administration users see itSeptember 5

    I need to change default functionality of statistics module. I want to count views of only published nodes by administration users too. I can't find any hook for this. Now if administration user see unpublished node, counter is increased. Is this pos

  • How to create slideshow with views using images from node's field February 20

    This question already has an answer here: Views slideshow from single node 8 answers I have a field in Page content type. Field's type is Image. It can contain unlimited number of images. I want to use this field for Slideshow (module views_slideshow

  • How to filter nodes with taxonomy term field in a view embedded on a node?

    How to filter nodes with taxonomy term field in a view embedded on a node?July 24

    I developing a Mp3 store with Ubercart 3. I have created an "Album" content type. I have another content Type called "Song". I want to embed a View within the "Album" node that will retrieve all songs belonging to that album.

  • how to create a view of entities and nodesSeptember 3

    I need to create a view which displays both entity type data and node data. Is this possible? I know how to create a view of either entities or nodes, but not together. --------------Solutions------------- Node are entities. Likely a Node View has ac

  • access the view but not the nodeOctober 11

    I have a view that displays a list of items. How to make anonymous user see this list of items but when accessing the node, it has to be logged? Any idea? I use the latest version of drupal --------------Solutions------------- You can disable node_ac

  • Drupal 7 - How to programmatically select a view display in a view based on some node data?October 31

    I have a content type that includes a field to store how that node should be displayed (display_option). display_option has two values (1|2). I have created a view with two displays. Both are pages. Both use the path /node/% and use the node id as a

  • Node's Preview when using Views module to render Node November 22

    I have been using Views module to render Node's Full content (using unformatted list of fields!). Seems that was not such a good idea. Now when I preview the Node, I see the Teaser and Full content Entity view modes (instead a View with fields). So t

  • How do I assign a view to a panel node in drupalNovember 23

    I have a panel that shows a teaser of a bunch of nodes of a certain content type. I am attempting to replicate this for a new content type. I have created a similar content type with the exact same fields. I have cloned the view(type = content pane)

  • How can I set the view mode of a node through rulesJanuary 14

    I'd like to change the view mode of a node based on the role of a user and another flag in the node, and by using the Rules module. Since a call to display the node by default is full content, I wrote a rule that on Content is Viewed for that node ty

  • alias the path of single - node views (pagination on single nodes)July 22

    I would like to effectively replace the nodes with views that would show the "full content" of a node with items to display set to 1. (Each paged page of the view would thus include only one node and the pager - effectivly i'm trying to use view

  • Multiple content types from Views module, not old nodes from one of them

    Multiple content types from Views module, not old nodes from one of themOctober 8

    I use the famous Views module to show nodes of different content types. One of these content types has a field called "final date". If a node has an old date, smaller than today's date, I want it to disappear from the start page so it's always u

  • How To Display Image instead of Taxonomy name using Views to display my nodes?November 7

    I Have Entity Module and already have a Taxonomy Vocabulary with terms and an Image Field created. Each term has a unique image. I Have a Content Type with a Term Reference field set to allow multiple selections of my Vocabulary. I now want to have m

  • Views: How to list nodes that are referencing to nodes, pointing to the current nodeJanuary 21

    I have 3 contenttypes where 2 of them have reference entity fields. Each their own entityfield. Contenttype C is the parent. Type B points to type C. Type A points to B. On every Node of type C i want to display a view that lists the nodes of type A

  • Views contextual filter - related nodes as an offset from a node's creation date

    Views contextual filter - related nodes as an offset from a node's creation dateJune 17

    I have a related content view which displays similar nodes based on shared taxonomy terms. I want it to display related nodes that were published in a date range relative to the current node's creation/published date. E.g: for a node published in Mar

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.513 s.