0

I've got a working email notification system built with flags and rules. The missing part in my puzzle is how to create a Views block showing the Flag links of the terms I've tagged a node with.

Example:

A node tagged with a Taxonomy Term - When users access that node I want a block displayed enabling them to flag/unflag the Term(s) in the node.

Here's a blog post mockup. It's the subscription block in the left side of the screen that I'm talking about.

blog post with subscription

I've got a block with all the Terms and their flag links but I can't figure out the right relationships and contextual filters to have only the used terms appear.

Here's the view I've created. The relationships and filters fail to only show the 1 term a node is tagged with. Instead it shows 3 of each term in the entire vocabulary.

$view = new view();
$view->name = 'subscription_block';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'taxonomy_term_data';
$view->human_name = 'Subscription block';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Subscription block';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'entity';
/* Relationship: Taxonomy term: Content using Artist */
$handler->display->display_options['relationships']['reverse_field_artist_tags_node']['id'] = 'reverse_field_artist_tags_node';
$handler->display->display_options['relationships']['reverse_field_artist_tags_node']['table'] = 'taxonomy_term_data';
$handler->display->display_options['relationships']['reverse_field_artist_tags_node']['field'] = 'reverse_field_artist_tags_node';
$handler->display->display_options['relationships']['reverse_field_artist_tags_node']['required'] = TRUE;
/* Field: Taxonomy term: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['name']['link_to_taxonomy'] = TRUE;
/* Contextual filter: Content: Has taxonomy term ID (with depth) */
$handler->display->display_options['arguments']['term_node_tid_depth']['id'] = 'term_node_tid_depth';
$handler->display->display_options['arguments']['term_node_tid_depth']['table'] = 'node';
$handler->display->display_options['arguments']['term_node_tid_depth']['field'] = 'term_node_tid_depth';
$handler->display->display_options['arguments']['term_node_tid_depth']['relationship'] = 'reverse_field_artist_tags_node';
$handler->display->display_options['arguments']['term_node_tid_depth']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['term_node_tid_depth']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['term_node_tid_depth']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['term_node_tid_depth']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['term_node_tid_depth']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['term_node_tid_depth']['validate']['type'] = 'taxonomy_term';
$handler->display->display_options['arguments']['term_node_tid_depth']['validate_options']['vocabularies'] = array(
  'artist_subscriptions' => 'artist_subscriptions',
);
$handler->display->display_options['arguments']['term_node_tid_depth']['depth'] = '0';
$handler->display->display_options['arguments']['term_node_tid_depth']['break_phrase'] = TRUE;
/* Filter criterion: Taxonomy vocabulary: Machine name */
$handler->display->display_options['filters']['machine_name']['id'] = 'machine_name';
$handler->display->display_options['filters']['machine_name']['table'] = 'taxonomy_vocabulary';
$handler->display->display_options['filters']['machine_name']['field'] = 'machine_name';
$handler->display->display_options['filters']['machine_name']['value'] = array(
  'artist_subscriptions' => 'artist_subscriptions',
);

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
1

I went from the other side, may work for you.

From Structure - Content type - Manage field; add existing field type Term reference and select the vocab. (you may already have done this)
--> Manage display, and set your term field to visible here. If you need, create a new display, say 'PagePlusTerms'.

Now in your View where you pull your data,
FORMAT-format= Unformatted list(whatever) and
FORMAT-show= Content | PagePlusTerms (where you pick the display you made just before for 'How should each row in this view be styled')

contextual filter: Content: Has taxonomy term ID (with depth):: Depth (0) : Allow multiple : Specify validation criteria - Term ID
and
Configure contextual filter: Content: Has taxonomy term ID depth modifier

see if that works for you


EDIT after more info:

Using your extra info and approach you can try (assumption: your node type(say Artist Node, has a field where taxonomies are added);

Create a new View with the 'Master'
Format - Show - Fields
and
Fields - Content: All taxonomy terms (Display all taxonomy terms associated with a node from specified vocabularies)
and
Filter Criteria - Content: Type(=Artist Node)

then add a 'Block' dispaly for the view, say 'Subscription blockII'
on which you add
Contextual filters: - Content: Nid
Configure contextual filter: Content: Nid
When the filter value is NOT available
Provide default value - type: Content ID from url

the block 'preview' in View may be blank, that's OK.
You can then add the block to your page on 'Artist Nodes'.

Basically you will then have a block that you can place anywhere on a node, which will look at the node id, then look for the taxonomies on that id and then print them in the block.
Hope I understood you correctly.

  • Hi @piet. Thanks for the effort. I can't get this working though. My View is still showing all terms and not just the one used in the node. And also, I'd like to only display the term in my Views block and not on the node itself. Any ideas? – Kristoffer Rom Jun 5 '15 at 23:41
  • can you then post explain how you got "I've got a block with all the Terms and their flag links but I can't figure out the right relationships and contextual filters to have only the used terms appear." ? – piet Jun 7 '15 at 10:35
  • Thanks for your time @Piet. I've edited my original post and provided more details. Hope it makes more sense now? – Kristoffer Rom Jun 7 '15 at 15:05
  • edit made after your extra info, sorry for the delay – piet Jun 12 '15 at 1:27
  • Thanks, your new approach works to show the term - but only the term. I need to show both the term and the flag. In my original view I'd achieved that by having a taxonomy term view showing the rendered entity. But that kind of view don't have the Content: Nid contextual filter. Any ideas? – Kristoffer Rom Jun 13 '15 at 20:58
0

Had a friend help me out, so posting his solution in case anyone else needs something similar. He got it working by doing a taxonomy term contextual filter with the following php in 'provide default value'

$node = menu_get_object(); return $node->field_artist_tags['und'][0]['tid'];

field_artist_tags is the machine name of my term field

That makes the term referenced by a node appear including the flag:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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