Taxonomy should provide a fallback way to display terms when Views is not enabled

Created on 10 October 2024, 3 months ago

Problem/Motivation

The taxonomy module has an optional view, views.view.taxonomy_term.yml that gets installed if the views module is enabled.

Terms are linked by default on the taxonomy listing pages to this view, and without the view, users are presented with broken links.

Steps to reproduce

Verify the Views module is not installed
Install the Taxonomy module
Create a Taxonomy and add terms
Create a Content type with a Term reference field to that taxonomy
Create a node and add terms to it
Save and view
Click on a term to be taken to a blank page

Proposed resolution

Discussed in Drupal slack at https://drupal.slack.com/archives/C2THUBAVA/p1728576208547489?thread_ts=...

catch

The answer would be for term pages to be a term entity view canonical URL, which then when views (+ XB) is enabled has the view underneath the term entity. (edited)

Or in a not-layout-builder/xb world, for term module to provide taxonomy/term/n that renders the term entity and then views overrides it.

I do think eventually we should have a term entity view that is XB enabled that then renders the view.

phenaproxima
I suppose we could just use a generic entity view builder for terms, as the fallback.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

taxonomy.module

Created by

🇺🇸United States thejimbirch Cape Cod, Massachusetts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @thejimbirch
  • 🇺🇸United States thejimbirch Cape Cod, Massachusetts
  • Assigned to Akhil Babu
  • 🇮🇳India Akhil Babu Chengannur

    Let me give this a try

  • 🇮🇳India Akhil Babu Chengannur

    I tried adding a new view bulder for terms like this
    Term.php

        'view_builder' => TaxonomyTermViewBuilder::class,
    

    TaxonomyTermViewBuilder.php

      /**
       * {@inheritdoc}
       */
      public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
        // Get all the nodes that use this term.
        $tid = $entity->id();
        $query = $this->database->select('taxonomy_index', 't')->fields('t', ['nid'])->condition('tid', $tid);
        $nodes = $query->execute()->fetchCol();
    
        // Render all the nodes in teaser view mode.
        $build = [];
        $view_builder = $this->entityTypeManager->getViewBuilder('node');
        foreach ($nodes as $node) {
          $node_entity = $this->entityTypeManager->getStorage('node')->load($node);
          $build[] = $view_builder->view($node_entity, 'teaser');
        }
    
        return[
          '#theme' => 'item_list',
          '#items' => $build,
        ];
      }
    

    The nodes are listed correctly when "Views" is not installed. However, the listing gets duplicated after installing 'views'. This could be fixed by simply checking whether the module is installed or not. but I am not entirely sure if this is the best solution.

  • 🇮🇳India Akhil Babu Chengannur
  • Pipeline finished with Failed
    8 days ago
    Total: 418s
    #372798
  • 🇮🇳India Akhil Babu Chengannur
  • Pipeline finished with Failed
    8 days ago
    Total: 425s
    #372805
Production build 0.71.5 2024