- Issue created by @thejimbirch
- Assigned to Akhil Babu
- 🇮🇳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.
- Merge request !10609Issues/3479980: Taxonomy should provide a fallback way to display terms when Views is not enabled. → (Open) created by Akhil Babu