Problem/Motivation

Currently it is impossible to access taxonomy vocabulary data as views fields - e.g. when trying to display a list of taxonomy terms with their related vocabulary names (Base table: taxonomy_term_field_data). Normally those should be available out-of-the-box as of the vid entity reference base field definition in Drupal\taxonomy\Entity\Term.

Proposed resolution

Make taxonomy vocabulary properties available as views fields.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

hctom created an issue. See original summary.

hctom’s picture

Issue summary: View changes
hctom’s picture

Issue summary: View changes
dawehner’s picture

One major difference between Drupal 7 and 8 here is that vocabularies are no longer stored in the database.
Given that vocabulary / node types ... etc. all don't have labels. Theoretically though you could write a generic bundle field handler, which can fetch the label, as needed.

webflo’s picture

daniel_rempe’s picture

Assigned: Unassigned » daniel_rempe

I try to take a step on this one.

daniel_rempe’s picture

Status: Active » Needs review
StatusFileSize
new775 bytes

Let's try this out

jeff cardwell’s picture

After adding the patch in #7, I was able to add a field for the vocabulary name in a view based on the table "taxonomy_term_field_data." However, the description appears as "Filter the results of 'Taxonomy: Term' to a particular vocabulary." which is incorrect. Also, the "category" might be more appropriately be "Taxonomy Vocabulary" rather than "Taxonomy Term."

dawehner’s picture

Oh that patch is interesting. I mean the patch solves some of the problems, other fields obviously would not be supported, but its certainly an improvement.

However, the description appears as "Filter the results of 'Taxonomy: Term' to a particular vocabulary." which is incorrect.

Do you mind explaining why this would be wrong? This is kinda what I think this particular filter would exactly do.

Also, the "category" might be more appropriately be "Taxonomy Vocabulary" rather than "Taxonomy Term."

Not sure about that to be honest. This kinda still is about the taxonomy term and having a category for just one field is kinda horrible.

daniel_rempe’s picture

It seems to be a problem with default permission checks. The entity reference formatter is called and requires a permission handler for vocabularies.

daniel_rempe’s picture

StatusFileSize
new2.55 KB

New patch with a vocabulary access control handler to grant view permissions for vocabularies on 'access content'.

Status: Needs review » Needs work

The last submitted patch, 11: 2658956-1.patch, failed testing.

daniel_rempe’s picture

StatusFileSize
new2.51 KB
new5.96 KB

Corrected patch format and added a test case patch.

daniel_rempe’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: 2658956-2-test.patch, failed testing.

tstoeckler’s picture

+ * Contains \Drupal\node\VocabularyAccessControlHandler.
...
+ * Defines the access control handler for the node type entity type.

Hehe :-), should be taxonomy and vocabulary, respectively.

daniel_rempe’s picture

Status: Needs work » Needs review
StatusFileSize
new8.49 KB

Fixed the copy & paste fragment. (Fix and test case included)

daniel_rempe’s picture

StatusFileSize
new8.5 KB

Added use statement in test case.

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Yay, thanks a lot! :-)

Bot can set this back to needs work, if it wants otherwise, this is good to go.

jeff cardwell’s picture

StatusFileSize
new85.6 KB
new138.41 KB

@dawehner
I admit that I am wading into something that I am mostly unfamiliar with but my comments were based on the the following screen shots from Views 3 in Drupal 7..

The description for the added field here differs from the description when the field is added as a filter.
Views Add Fields

Views add Filters

It appears to me that the patch only addresses making the vocabulary name available in the "fields" section as it is already available in the "filters" section.

Additionally, while I agree that having a different category for one field is weird, I wasn't sure if there were plans to add the additional vocabulary properties that are available "out-of-the-box" in Views 3 for D7 in what I believe to be the same scenario. If that were the case, I would think that a separate category would be appropriate.

Of course, the new way that vocabularies are being dealt with in Drupal 8 may just mean that I'm confused... And if I am, no worries. I'll try not to clog up this queue with my misunderstanding. :)

dawehner’s picture

The patch as it is looks totally alright for me.

stborchert’s picture

hctom’s picture

The patch applies cleanly without problems. Thanx for all your hard work.

But I also have to admit, that the field description is not really helpful, as it targets the filter and not the field.

tstoeckler’s picture

Status: Reviewed & tested by the community » Needs work

Re @stBorchert #22: I wasn't aware of the other issue. I spoke to @Daniel_Rempe in person about this and he will post an updated patch which just "enables" the field, not the contextual filter or the sort. That means we should open another issue about the sort (including test coverage). Marking "needs work" until such an updated patch is posted.

daniel_rempe’s picture

Status: Needs work » Needs review
StatusFileSize
new8.44 KB

Changed the field description to 'The vocabulary name' and removed the parts concerning sorts and filters.

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, let's get it in!

  • catch committed 2aa26f3 on 8.1.x
    Issue #2658956 by Daniel_Rempe: Taxonomy vocabulary data not available...
catch’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x, thanks!

I didn't commit this to 8.0.x because it has the string addition etc.

jibran’s picture

Version: 8.1.x-dev » 8.0.x-dev
Status: Fixed » Patch (to be ported)
+++ b/core/modules/taxonomy/src/TermViewsData.php
@@ -71,7 +71,7 @@ public function getViewsData() {
+    $data['taxonomy_term_field_data']['vid']['field']['help'] = t('The vocabulary name.');

Let's remove this string and fix the bug in 8.0.x.

catch’s picture

Version: 8.0.x-dev » 8.1.x-dev
Priority: Normal » Critical
Status: Patch (to be ported) » Needs review
Issue tags: +beta target
StatusFileSize
new8.46 KB

This need rolling back:

+++ b/core/modules/taxonomy/src/Entity/Vocabulary.php
@@ -20,6 +20,7 @@
+ *     "access" = "Drupal\taxonomy\VocabularyAccessControlHandler",

This isn't enough since the default permission is 'view content'. So going to roll back.

I got a merge conflict with git revert, so here's a rollback patch. Bumping to critical so it doesn't get forgotten.

Status: Needs review » Needs work

The last submitted patch, 30: 2658956.patch, failed testing.

catch’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 30: 2658956.patch, failed testing.

catch’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 30: 2658956.patch, failed testing.

catch’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 30: 2658956.patch, failed testing.

catch’s picture

Status: Needs work » Needs review

Can't reproduce the 8.1.x fail and 8.2.x passes. So back to CNR and sent for another retest.

Status: Needs review » Needs work

The last submitted patch, 30: 2658956.patch, failed testing.

catch’s picture

Status: Needs work » Needs review
catch’s picture

Figured out why so many re-tests failed. If an issue is at 8.0.x, then you move it to 8.1.x when submitting a patch, retest tests against 8.0.x

catch’s picture

Status: Needs review » Reviewed & tested by the community

Since I only did a re-roll because git revert didn't work, and all tests green now, moving to RTBC.

alexpott’s picture

Priority: Critical » Normal
Status: Reviewed & tested by the community » Needs work

Committed the revert a2d1d2e and pushed to 8.1.x and 8.2.x. Thanks!

  • alexpott committed 920edd9 on 8.2.x
    Revert Issue #2658956 by Daniel_Rempe, catch, Jeff Cardwell, hctom,...
tstoeckler’s picture

Could someone elaborate on the rollback? I'm afraid I don't really understand what #30 is trying to say.

catch’s picture

/**
 * Defines the access control handler for the taxonomy vocabulary entity type.
 *
 * @see \Drupal\taxonomy\Entity\Vocabulary
 */
class VocabularyAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    switch ($operation) {
      case 'view':
        return AccessResult::allowedIfHasPermission($account, 'access content');
        break;

      default:
        return parent::checkAccess($entity, $operation, $account);
        break;
    }
  }

}

This meant that anonymous users could view admin/structure/taxonomy/$vocabulary since that relies only on the view permission.

tstoeckler’s picture

Ahh OK, thanks. I understand. That's certainly not ideal.

  • catch committed 2aa26f3 on 8.3.x
    Issue #2658956 by Daniel_Rempe: Taxonomy vocabulary data not available...
  • alexpott committed 920edd9 on 8.3.x
    Revert Issue #2658956 by Daniel_Rempe, catch, Jeff Cardwell, hctom,...

  • catch committed 2aa26f3 on 8.3.x
    Issue #2658956 by Daniel_Rempe: Taxonomy vocabulary data not available...
  • alexpott committed 920edd9 on 8.3.x
    Revert Issue #2658956 by Daniel_Rempe, catch, Jeff Cardwell, hctom,...
xjm’s picture

Version: 8.1.x-dev » 8.3.x-dev
Issue tags: -beta target

Fixing metadata since this is an 8.3.x issue at this point.

mikeker’s picture

Assigned: daniel_rempe » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.11 KB
new9.05 KB

I think the issue is that the vocabulary overview page (route entity.taxonomy_vocabulary.overview_form) is not really an overview page but a page where you can rearrange the terms in a vocabulary. If we change the _entity_access permission to update instead of view, that should solve anonymous access to that page. Also fixed a copy/paste leftover in the test.

berdir’s picture

Status: Needs review » Needs work

Not quite sure yet about the change, but we definitely need test coverage for the access check of that page then.

berdir’s picture

Actually, #2599128: Allow user with edit terms permission to access vocabulary overview does basically that and implements the view operation. I think we should wait on that issue and extend the test coverage there a bit more on anonymous access, get that in and then this will be fine as it was before (after merging the access control handler, that is)

  • catch committed 2aa26f3 on 8.4.x
    Issue #2658956 by Daniel_Rempe: Taxonomy vocabulary data not available...
  • alexpott committed 920edd9 on 8.4.x
    Revert Issue #2658956 by Daniel_Rempe, catch, Jeff Cardwell, hctom,...

  • catch committed 2aa26f3 on 8.4.x
    Issue #2658956 by Daniel_Rempe: Taxonomy vocabulary data not available...
  • alexpott committed 920edd9 on 8.4.x
    Revert Issue #2658956 by Daniel_Rempe, catch, Jeff Cardwell, hctom,...

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.

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.

berdir’s picture

#1848686: Add a dedicated permission to access the term overview page (without 'administer taxonomy' permission) now solves the overview problem, so once that is in, this issue can focus on the vocabulary name problem. #2808217: To be able to view Vocabulary config entities via REST, one should not have to grant the 'administer taxonomy' permission is also a related issue which wants to do basically the same.

A possible fix for this would also be to use the new view label operation, which is now respected by the entity label formatter thanks to #2692091: Use the new 'view label' entity access check in the entity reference label formatter.

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.

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new8.12 KB

Reroll was needed and serious refactoring after all the other issues have landed (so no interdiff). Also converted the test to a kernel test.

s.messaris’s picture

Thanks for the patch in #60, worked like a charm for my needs. +1 for RTBC.

ifrik’s picture

Status: Needs review » Reviewed & tested by the community

The patch works for me. By adding a relationship for the taxonomy term, it becomes possible to add the vocabulary as a field.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 60: 2658956-60.patch, failed testing. View results

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new718 bytes
new8.11 KB

Removed the deprecated call

s.messaris’s picture

Status: Needs review » Reviewed & tested by the community

Removig the deprecated call is reasonable. Setting back to RTBC.

  • catch committed 4dc2f4a on 8.6.x
    Issue #2658956 by Daniel_Rempe, Lendude, mikeker, catch, Jeff Cardwell,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 4dc2f4a and pushed to 8.6.x. Thanks!

hctom’s picture

Thanks for all you hard work on this - happy to see it merged now!

jibran’s picture

I have two questions:

  1. We are updating views data here which is cached so why don't we have an update hook to clear the cache?
  2. It is a bug so why are we not backporting it to 8.5?
jibran’s picture

Status: Fixed » Needs work
Issue tags: +Needs upgrade path

We do need an update hook see views_update_8004, views_update_8005 and views_update_8100

jibran’s picture

Status: Needs work » Needs review
Issue tags: -Needs upgrade path
StatusFileSize
new488 bytes

Here you go

berdir’s picture

Status: Needs review » Reviewed & tested by the community

To be honest, I don't really understand the policy to do this, as afaik the recommendation is that you should always clear caches when updating. Then again, drush updb is "intelligent" enough to not clear caches if there are no updates.

But it is consistent with what we did elsewhere AFAIK.

hctom’s picture

Status: Reviewed & tested by the community » Needs work

@Jibran: According to the change record https://www.drupal.org/node/2960601 cache clears shouldn't be executed via update hooks anymore. It is recommended to use hook_post_update_NAME instead. Perhaps this should be used instead.

jibran’s picture

Status: Needs work » Reviewed & tested by the community

@hctom I wonder who worte that change record 🤔. HOOK_update_N and HOOK_post_update_NAME both are called update hooks and yes, I have implememted HOOK_post_update_NAME in the patch :). Please have a look at the patch once again.

hctom’s picture

@jibran: i'm really sorry - i guess i shouldn't write in the issue queue that late at night ;) of course your patch is totally okay!

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 679fe1f and pushed to 8.6.x. Thanks!

  • catch committed 679fe1f on 8.6.x
    Issue #2658956 by Daniel_Rempe, Lendude, mikeker, catch, jibran, Jeff...
jibran’s picture

As per https://www.drupal.org/core/backport-policy, @catch can you please state your reason to not backport this to 8.5.x? I don't think this is disruptive at all.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.