I create a content type with a "field collection" field. Then I configured this "field collection" field to consist of a "Title", an "Image" and a "Taxonomy" field. Then I created a node of the new content type. I added a few "Field collection" items, gave each of them some Taxonomy terms.

When I now go to taxonomy/term/2 I get an empty page and the text "There is currently no content classified with this term."

But when I look at my node I see the added "field collection" items and the Terms they have.

Expected Behavior: "field collection" items that have Taxonomy Terms applied should show up on the corresponding taxonomy listing

CommentFileSizeAuthor
#8 copy_tags.txt854 bytesoda
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kaplingat’s picture

I too am facing this issue. It seems taxonomy field in a field collection entity is not getting associated with the node entity which contains the collection entity.

RobW’s picture

Since field collections' child fields are not really embedded in the $node object, this makes sense. A field collection field contains only a entity uri used to reference the content / child fields of a field collection entity. So the node itself does not actually contain any of the field collection's taxonomy fields, and the taxonomy listing is probably filtering for only nodes, not module-provided entities.

If #1047784: [Meta] Views Integration for field collection is settled you would be able to get this functionality with views relationships.

fago’s picture

Status: Active » Closed (works as designed)

This is - by design - of drupal core. Core taxonomy only lists nodes there, nothing field-collection can do about.

Views might be certainly a way out.

Jessica A’s picture

Anyone know how to get this functionality using views?

zmove’s picture

On a module developper side, it make sense that a field collection with a taxonomy would not associate the node to the taxonomy because it's an entity.

But on a drupal user side, that use field collection to merge several fields and extend core fields feature. It would be nice to have an out of the box way associate the node with the taxonomy terms added in a field collection, because this is the behavior that +95% people will want when adding a taxonomy term to a field collection.

I think the best way to do it is not to use views, but to use rules. To add or remove terms to the node on creation or update event. It would be less ressource intensive than creating the relation with views and calculate it for each node listing that will need it.

Maybe an exemple rule could be created for people that want to do it.

jsheffers’s picture

Has there been any update on this? Can it be done with views or panels? Any ideas how to achieve what @zmove reccomended in the above comment to attach those terms to a node using rules?

thatjustin’s picture

Anyone know how to do what zmove described in #5?

oda’s picture

Component: Miscellaneous » User interface
FileSize
854 bytes

thatjustin, just install rules module and create a new rule ;)

I'm attaching an example. To use it just add a field collection (in my rule example its named is "field_album_fields") to your content type, then add the field_tag to this field collection.

Hope this helps!

oda’s picture

Component: User interface » Miscellaneous

damn

thoughtcat’s picture

Hi oda, thanks for pasting that code. Where do I use it exactly? I've tried creating a new rule but I'm getting lost trying to translate your code into the steps required to create a rule using the rules UI. I can't see anywhere I can just paste your code into my site somewhere and modify it.

My field collection is called "field_personnel". Do I have to add a new field to the collection called "field_tags" to get this to work?

Many thanks.

thoughtcat’s picture

Ignore my last post, I've found out how to import a rule. I've pasted oda's code and changed the field names to reflect my own fields, but am getting "Integrity check for the imported configuration failed. Error message: The data type of the configured argument does not match the parameter's list requirement.."
These are what I changed:

  • where oda had "field_album_fields" (for the name of the field collection) I have "field_personnel"
  • where oda had "field_tags" I have "field_performername" for ONE of the term reference fields in my field collection (I'm assuming I have to set up a separate rule for each of the term references in the collection?)
  • where oda had "node:field-album-fields" I have "node:field-personnel"
  • where oda had "field:field-tags" I have "field:field-performername"

Any ideas?
Thanks :)

alpp’s picture

i also had the same error while trying to import the rule above.

oda, can you please give us some hints on the loop and actions that you used in that rule?

errand’s picture

Hello!
Any with this problem?

alpp’s picture

do you think this will be accomplished in drupal 8?

matt2000’s picture

Issue summary: View changes
Status: Closed (works as designed) » Needs work

The actual issue is that the node/term relationship doesn't get written to the core taxonomy_index table when the term field is part of a field collection. Field Collection needs to handle this with code similar to what EntityReference module has.

andileco’s picture

Hey All,

I was able to use this module (https://drupal.org/project/taxonomy_entity_index) to help me overcome this issue--it worked with term references but not entity references. Maybe some of the code from this module could be incorporated into field collection--or at least it might spark some ideas.

daulet2030’s picture

How exactly did you solve this issue andile2012? I installed entity index module and indexed everything, i still cant see nodes that have the term in a field collection on its term page.
Could you describes steps needed?

andileco’s picture

Thanks, @daulet2030, for your question. Looking back, it didn't do exactly what I thought it did... I can show nodes tagged by terms from a term reference field included in the field collection, but it only works for nodes that contain the field collection. Let me explain:

Assume:
ContentType1 - contains a field collection called "Languages", with a term reference field called "Language" (which references a vocabulary called "Language") and a list (integer) field called Skill Level

ContentType2 - also contains field collection "Languages"

ContentType3 - contains a term reference field for the "Language" vocabulary

--> You can use Taxonomy Entity Index to create a view that shows all nodes tagged using the Language term reference field within the Languages field collection (see code below) - so you will see nodes of ContentType1 and ContentType2, but none of ContentType3

...so it's not a great solution for most sites...it doesn't do what I was thinking it did.

But this may still be useful. I didn't see how to form the correct relationships to do this without the module. But I could have very easily missed something.

OK, code below:


$view = new view();
$view->name = 'taxonomy_term';
$view->description = 'A view to emulate Drupal core\'s handling of taxonomy/term.';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Taxonomy term';
$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['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['empty'] = TRUE;
$handler->display->display_options['empty']['area']['content'] = 'it is not working';
$handler->display->display_options['empty']['area']['format'] = 'filtered_html';
/* Relationship: Content: Languages (field_languages) */
$handler->display->display_options['relationships']['field_languages_value']['id'] = 'field_languages_value';
$handler->display->display_options['relationships']['field_languages_value']['table'] = 'field_data_field_languages';
$handler->display->display_options['relationships']['field_languages_value']['field'] = 'field_languages_value';
$handler->display->display_options['relationships']['field_languages_value']['delta'] = '-1';
/* Relationship: Taxonomy Entity Index: Taxonomy terms on Field collection item */
$handler->display->display_options['relationships']['taxonomy_entity_index_entity_tid_1']['id'] = 'taxonomy_entity_index_entity_tid_1';
$handler->display->display_options['relationships']['taxonomy_entity_index_entity_tid_1']['table'] = 'field_collection_item';
$handler->display->display_options['relationships']['taxonomy_entity_index_entity_tid_1']['field'] = 'taxonomy_entity_index_entity_tid';
$handler->display->display_options['relationships']['taxonomy_entity_index_entity_tid_1']['relationship'] = 'field_languages_value';
/* Sort criterion: Content: Sticky */
$handler->display->display_options['sorts']['sticky']['id'] = 'sticky';
$handler->display->display_options['sorts']['sticky']['table'] = 'node';
$handler->display->display_options['sorts']['sticky']['field'] = 'sticky';
$handler->display->display_options['sorts']['sticky']['order'] = 'DESC';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Taxonomy Entity Index: Has taxonomy term ID on Field collection item (with depth and indexed in taxonomy_entity_index) */
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['id'] = 'taxonomy_entity_index_tid_depth_1';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['table'] = 'field_collection_item';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['field'] = 'taxonomy_entity_index_tid_depth';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['relationship'] = 'field_languages_value';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['default_action'] = 'empty';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['title_enable'] = TRUE;
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['title'] = '%1';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['validate']['type'] = 'taxonomy_term';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['validate']['fail'] = 'empty';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['depth'] = '0';
$handler->display->display_options['arguments']['taxonomy_entity_index_tid_depth_1']['break_phrase'] = TRUE;
/* Filter criterion: Content: Published or admin */
$handler->display->display_options['filters']['status_extra']['id'] = 'status_extra';
$handler->display->display_options['filters']['status_extra']['table'] = 'node';
$handler->display->display_options['filters']['status_extra']['field'] = 'status_extra';
$handler->display->display_options['filters']['status_extra']['group'] = 0;
$handler->display->display_options['filters']['status_extra']['expose']['operator'] = FALSE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'taxonomy/term/%';

/* Display: Feed */
$handler = $view->new_display('feed', 'Feed', 'feed');
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = 15;
$handler->display->display_options['style_plugin'] = 'rss';
$handler->display->display_options['row_plugin'] = 'node_rss';
$handler->display->display_options['path'] = 'taxonomy/term/%/%/feed';
$handler->display->display_options['displays'] = array(
  'page' => 'page',
  'default' => 0,
);



znerol’s picture

I've posted a simple module capable of adding terms on entities nested within nodes to the taxonomy_index.

Marko B’s picture

Did somebody try to solve issues here with this module in the end, that uses SHS ?

https://www.drupal.org/node/1354446

haunted’s picture

@zenerol
Your module works perfectly for my field collection's taxonomy terms, thank you!

aruiz360’s picture

Hi everyone.
I had the same problem but solved it another way.
Just add a relationship: the field with the term reference.
Then filter the content not by Has taxonomy term but by the term itself.

Thanks to everybody for the help!

kaztur’s picture

#19 works for me. Great thank You, @znerol!

ladybug_3777’s picture

Update: The module Taxonomy Deep Index: https://www.drupal.org/project/taxonomy_deep_index has an issue with writing duplicate entries to the taxonomy_index table that I just discovered. See this post: https://www.drupal.org/node/2399655

For me, until that issue is resolved, it isn't a viable solution yet.

UPDATE: There has been a fix released for the module issue above.

rivedav’s picture

I have the same issue with Drupal 8. Does anybody have an Idea to solve this issue: Fieldcollection items that have a taxonomy field assigned and a term given are not shown on the corresponding taxonomy page nor any views created

ladybug_3777’s picture

Rivedav,
It doesn't look like Taxonomy Deep Index has a version 8 module :-( That's what I ended up having to use to get this fixed in version 7.

Not sure how hard it would be to upgrade the taxonomy deep index module to work with 8.... but maybe ask about it in that issue queue?

haunted’s picture

@rivedav You can create view that overrides the taxonomy term page.

You have to make a view of contents, set the page url as Path: /taxonomy/[vocabulary name]/%, add the relationship between the content and the field collection field, and then a relationship between the field collection field and the field collection item (the term reference field).

Then you have to add a contextual filter for the field collection item (the term reference field) and tell it to grab the taxonomy term id from the url.

The problem is that this will override all the vocabularies unless you use also a module like https://www.drupal.org/project/taxonomy_display , but this has not been ported to drupal 8 yet.

ABaier’s picture

I tried the solution proposed in #27 and it worked as long as I defined it only for one vocabulary. In my case (drupal 8.15) I have three field collections in my node type with each an other term reference field, sorted in individual vocabularies. So I basically want to override the general handling of the taxonomy pages to target all of them. But if I duplicate the first view, change the url pattern to the next vocabulary name and reset the contextual filter and relationships to the specific fields, none of the views would show contents anymore. Would this also be possible in a single view? I don't know if it is possible to set multiple contextual filters and define them with an OR statement …

Another thing I would like to achive is, that the original url pattern for the taxonomy terms (/taxonomy/term/id) is kept, so that the links of the terms target the right pages, so that I don't have to set them individually.

Any help appreciated! Thanks in advance.

jmuzz’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev

Just to clarify, this issue is about getting the nodes that contain the field collection with the term to appear on the taxonomy page, right?

That seems to be what the comments suggest, and if that's the case I agree with #15 it should be the behaviour. #2509254: Field collection fields should extend entity reference fields

The issue summary talks about getting the field collection items themselves on the taxonomy pages. I think that was the understanding behind #3 and that is not something we can support.

ABaier’s picture

You are right @jmuzz. The nodes containing the field collection with the term field should appear on the taxonomy pages. Like they would show up, if the term reference would be placed into the node directly.

jmuzz’s picture

Version: 8.x-1.x-dev » 8.x-3.x-dev

Development is moving to 8.x-3.x.

alpp’s picture

Will this issue be solved in 8.x-3.x. version?

ram4nd’s picture

Status: Needs work » Closed (won't fix)