Problem/Motivation

Adding a Term reference field is not working as expected: link on profile page leads to taxonomy/term page which says "There is currently no content classified with this term."

Proposed resolution

There are 2 different solutions:
- create a custom view for the taxonomy/term/% pages;
#1016942: Allow taxonomy/term pages to list multiple entity types
- change core to show not only 'node' entities;
#1137558: Show multiple entity types on Core taxonomy/term pages, not just 'node'

See above.

CommentFileSizeAuthor
#37 Screenshot.png97.7 KBgaele
#30 term_pages.zip1.87 KBgaele

Comments

swentel’s picture

taxonomy_term_page() only looks for nodes. Users aren't probably classified as content. Could be easily done with views of course overriding the taxonomy term path.

rosk0’s picture

I thought so too,but after about two hours of trying to do this(with different version of views) am still at the beginning with no result. could you help me please?

stevenpatz’s picture

Category: bug » support
Anonymous’s picture

There are perhaps multiple ways to accomplish this. They all will require writing a module I think, but in any case, you're going to be able to copy and paste code from Drupal 7 core and tweak it in simple ways.

You need to create a view or page callback that lists the entities that have this term value. Create a new formatter in your module that links to this view or page callback. Copy the code in taxonomy.module that's related to the formatter hooks:

taxonomy_field_formatter_info
taxonomy_field_formatter_view
taxonomy_field_formatter_prepare_view

Put these in the new module. Rename them. Cut out the formatter you don't want (the plain one) and hack around the one named taxonomy_term_reference_link. Instead of linking to entity_uri()'s return value, it needs to link to 'my-custom-view-of-users/'. $term->tid. Rename the taxonomy_term_reference_link when making your changes, too. It has to be named something besides taxonomy_term_reference_link. Then use this formatter for the taxonomy term field on your user entities.

There may be other ways, but they will always require a working view or page callback that takes the term as an argument. For example, i'd also investigate using hook_entity_info_alter() to add a new uri callback specific to the user entity and bundle. I don't know how that would work, but it appears at first glance to be possible.

rjbrown99’s picture

#7, we are now 8 months out from your advice. Do you still view that as the approach, or has a new module or functionality come along to provide that missing feature? I'm about to slog into term reference tied to users. If there is a shortcut I'd like to take it rather than writing a module :) Thanks.

cmacdonald’s picture

I'm up against the same issue, but I don't really have the expertise to write a new module. Are there any other workarounds for this that I could try?
Thanks.

cmacdonald’s picture

I ended up using the Profile2 module, and creating a drop down list field for my user types in the profile.

Then I created separate views for each user type based on the value of that field.

More work, but probably less than writing a new module.

skizzo’s picture

Just moving into D7 and I am facing the same problem. If I understand it correctly, provide term relationship via taxonomy term reference fields should allow to solve the problem with Views, without additional modules. Could someone please confirm my understanding? If so, please change this issue status.

xjm’s picture

Status: Active » Closed (works as designed)

Yes, this should be doable with views.

gaele’s picture

Title: Term reference field in user profile » Term reference field on non-node entity is not working as expected
Version: 7.0 » 7.x-dev
Category: support » bug
Status: Closed (works as designed) » Active
joachim’s picture

Status: Active » Closed (works as designed)

The design of taxonomy is that you tag content and list it. If you want to apply terms to other types of entity, then you need to either use the formatter that doesn't have a link, or do something else. In more advanced site designs, taxonomy isn't even shown, it's just used as dropdowns for filtering by and so on.

> Do you still view that as the approach, or has a new module or functionality come along to provide that missing feature? I'm about to slog into term reference tied to users. If there is a shortcut I'd like to take it rather than writing a module :) Thanks.

The shortcut is writing the module and sharing it on d.org for others to use and contribute to.

gaele’s picture

Version: 7.x-dev » 8.x-dev
Status: Closed (works as designed) » Active
Issue tags: +D8UX usability

joachim, please let others have a chance to have a look at it.

> The design of taxonomy is that you tag content and list it.

This is how it used to be in D6. In D7 the ability to tag other entity types was added. My impression is that the taxonomy term page was just left as is, without a conscious decision (but then again I may be wrong).

This probably won't get solved in D7. For D8 we need a more fundamental discussion about where a term reference field should link to (all entities, current entity type, ...). If nothing changes we need Drupal to not let people like the issue starter make mistakes and get unexpected results.

xjm’s picture

Title: Term reference field on non-node entity is not working as expected » Make taxonomy term pages list non-node entities
Category: bug » feature

If this were the case, there'd also likely need to be indexes for non-node entities. See also #1040786: Include entities in taxonomy_index.

scottrouse’s picture

+1 to this request.

It seems like an obvious oversight in D7 to me. What's the point of being able to add a term reference field to an entity other than a node if it doesn't show up on a taxonomy page? There would be no other benefit that I can see to choosing term reference over just an option list with a View created to filter on those options.

Sylense’s picture

+1

xjm’s picture

For those adding +1 above, please do keep in mind this should already be doable with Views, which will provide flexibility and configurability that core probably won't. Edit: Also, I believe the fact that term listing pages list only nodes was a design choice for D7. That is why this issue is a feature request.

xjm’s picture

I added this issue at #1347448: [META] Taxonomy admin usability Improvements since it does cause confusion, as the issues @gaele links indicate.

gaele’s picture

Based on #7 I have created a module that provides a new field formatter for a term reference field: http://drupal.org/sandbox/gaele/1377430.

After installing the module you will have a new format "Link (to custom path)" on the "Manage display" tab. Use this to specify a path to a view.

I have successfully used this module to link a term reference field on profiles to a view of profiles.

Note that this is still just a workaround. This should be fixed in a more fundamental way in D8.

joachim’s picture

I think that module is going to be tremendously useful no matter what core does -- think of times when you want terms from vocab A to link to view A, and those in vocab B to link to view B.

@gaele: if you don't yet have permission to create full projects, want to file a request for that sandbox to be reviewed? I'd be happy to review it.

skizzo’s picture

see also entity_path

gaele’s picture

skizzo, thank you for the link to entity_path. I think it is more useful than my module. Though perhaps a bit more difficult to configure.

This is what I did:

1. create a view accepting a taxonomy term argument, configured as "Term name converted to Term ID".
2. install the entity_path module, go to admin/config/content/entity_path and "Add".
3. Instance: choose a vocabulary under "Taxonomy term (taxonomy_term)".
4. Path pattern: /[term:name]
5. Check "Space Separator" with Separator character "-", and Path case "Lowercase".

joachim’s picture

Entity path looks interesting, but I think doing it as a formatter covers more ground.

Consider for example the 'Drupal core version' vocabulary on d.org (when d.org is upgraded to D7... ;).
When applied as a term reference to project pages, it could link to a view of project pages; then applied as a term to documentation pages, it could link to a view of documentation. That is doable with field formatters because they are per-instance of the reference field, whereas with Entity path, a term such as '6.x' always links to the same place.

diskojerk’s picture

@gaele #24

How did this method work for you? Did you get the expected result?

gaele’s picture

Yes, Entity path is working for me. I'm using a vocabulary specifically for profiles: http://socialhistory.org/en/staff.

See joachim's remark for other uses. (If more people are interested in my module I will create a full project.)

skizzo’s picture

Johachim's remarks make sense. It seems to me that term_pages and entity_path do address different use cases. I tried your module from git repository: it works fine for plain taxonomies, but I couldn't apply it to my hierarchical taxonomies. Maybe a "Hierarchical Link (to custom path)" could also be provided?

j4’s picture

Please am not used to git. Can you post a zipped version of the folder here instead which I can download and try?

Thanks and yes I would like to add my vote that is facility is a must, if we are allowed to add term reference to profile types.

Thanks
Jaya

gaele’s picture

StatusFileSize
new1.87 KB
joachim’s picture

Regarding linking your taxonomy terms to Views that list other things: I made this last week http://drupal.org/project/field_formatter_value_link

It could do with a patch to pass in the term ID rather than the term name. You could probably get Views to accept the term name though.

onelittleant’s picture

For those looking to do this in D7...

This can be achieved with views and http://drupal.org/project/taxonomy_display in little time.

A bit more challenging is making the view you use to replace the taxonomy/term view show more than one entity type, though it can be done if you make the taxonomy term the base table and relate it to multiple entity types via a shared term reference field.

xjm’s picture

Status: Active » Closed (won't fix)

With Views being moved into core in Drupal 8, this issue will be fixed by that. We'll convert the taxonomy/term listing to a view, and then it will be possible to modify it to list other entity types. :)

For details, see: http://www.angrydonuts.com/vdc-update-and-announcement

joachim’s picture

> We'll convert the taxonomy/term listing to a view, and then it will be possible to modify it to list other entity types. :)

Not really.

Views can have only one base table.

One cheat would be to use taxonomy term as the base, the term ID of what you're looking at as the argument, and then add a relationship for each entity type you want to list.

But then you couldn't sort them by post date or anything meaningful like that because you wouldn't have common table columns.

Then again, that bit wouldn't be possible with raw SQL queries either.

gaele’s picture

Title: Make taxonomy term pages list non-node entities » Term reference field on non-node entity is not working as expected
Status: Closed (won't fix) » Active

The confusion for users still needs to be resolved. Let's keep this on the list at #1347448: [META] Taxonomy admin usability Improvements.

hoff331’s picture

@gaele #24

Can you please clarify "1. create a view accepting a taxonomy term argument, configured as "Term name converted to Term ID"."

gaele’s picture

StatusFileSize
new97.7 KB

@hoff331: in the example below Department is a term reference field.

configure contextual filter

xjm’s picture

Title: Term reference field on non-node entity is not working as expected » Allow taxonomy/term pages to list multiple entity types

Clarifying the title.

johnv’s picture

Title: Allow taxonomy/term pages to list multiple entity types » How to: Allow taxonomy/term pages to list multiple entity types using Views 3

The following issues have the same problem, but they propose different solutions. Hence, a more explicit title:
- this issue: #1016942: Allow taxonomy/term pages to list multiple entity types
- other issue: #1137558: Show multiple entity types on Core taxonomy/term pages, not just 'node'

marcingy’s picture

Title: How to: Allow taxonomy/term pages to list multiple entity types using Views 3 » Allow taxonomy/term pages to list multiple entity types

Views 3 is contrib what is in core is views so a reference to views 3 is pointless in the title, although the linked issues are useful.

joachim’s picture

Views can't mix base tables.

One possible -- but fairly ugly -- way to do this would be by making the taxonomy term be the base, and then add relationships to multiple entity types.

You'd then use the 'rendered entity' field (IIRC there is one), which you'd add once for each relationship, and you'd need to make sure that all the empty fields don't output anything.

coolhandlukek2’s picture

+1

coolhandlukek2’s picture

Issue summary: View changes

Added summary template headers
Added reference to other issue

jibran’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes
Status: Active » Postponed
Related issues: +#1040786: Include entities in taxonomy_index

Well taxonomy/term page is converted to view in #1857256: Convert the taxonomy listing and feed at /taxonomy/term/%term to Views. The query for the page is

SELECT taxonomy_index.sticky AS taxonomy_index_sticky, taxonomy_index.created AS taxonomy_index_created, node.nid AS nid
    -> FROM 
    -> node node
    -> LEFT JOIN taxonomy_index taxonomy_index ON node.nid = taxonomy_index.nid
    -> WHERE (( (taxonomy_index.tid = '1') )AND(( (taxonomy_index.status <> '0') )))
    -> ORDER BY taxonomy_index_sticky DESC, taxonomy_index_created DESC
    -> LIMIT 11 OFFSET 0;

In theory we can use other entities now but taxonomy_build_node_index is hardwired for node and taxonomy_index is infect taxonomy_node_index so we can't really use other entities. Perhaps after #1040786: Include entities in taxonomy_index it's possible so postponing it on #1040786 which I just moved to 8.1.x.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

heddn’s picture

Status: Postponed » Active

I don't think this needs to be postponed any more.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

johnpitcairn’s picture

@Joachim:

One possible -- but fairly ugly -- way to do this would be by making the taxonomy term be the base, and then add relationships to multiple entity types. You'd then use the 'rendered entity' field (IIRC there is one), which you'd add once for each relationship, and you'd need to make sure that all the empty fields don't output anything.

This does not seem to be possible if one entity type is a node. To get any results for nodes the relationship needs to be required because of #1349080: node_access filters out accessible nodes when node is left joined.

ytsurk’s picture

To overwrite the default taxonomy/term/% view, the forum module uses a nice approach by providing a RouteSubscriber. #2010132: Canonical taxonomy term link for forum vocabulary is broken

Still the view then needs a relation using the desired field (taxonomy reference) ..

lukasss’s picture

Sadly, that question stretches back to the 7 version

ytsurk’s picture

lukasss’s picture

I need D8!

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

marcoscano’s picture

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

axel80’s picture

I think now this is quite important, especially with Media in core

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.