[2.0.x] Add support for Taxonomy Terms

Created on 29 June 2023, 12 months ago
Updated 5 July 2023, 12 months ago

Problem/Motivation

Currently, "getSupportedEntityTypes()" in "/src/EntityHelper.php" will ignore some entity types that were originally compatible with rabbit_hole 1.x, like Taxonomy Vocabulary (Or rather taxonomy terms) through the submodule "rh_taxonomy" for example:

This is because only Entity Types implementing "ContentEntityTypeInterface" and having the "canonical" link template implemented, will get returned as a supported entity type. Taxonomy Term does not have the 'canonical' link template implemented and is therefore not supported and not displayed on the rabbit hole settings page. This breaks compatibility with modules like "rabbit_hole_href".

The settings page without "Taxonomy Term":

Steps to reproduce

Proposed resolution

Add support for Taxonomy Terms.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Closed: works as designed

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Grevil

Live updates comments and jobs are added and updated live.
  • Regression

    It restores functionality that was present in earlier versions.

Sign in to follow issues

Comments & Activities

  • Issue created by @Grevil
  • πŸ‡©πŸ‡ͺGermany Grevil

    Setting this to "Major" as it is a major regression from 1.x and breaks compatibility with submodules like "rabbit_hole_href".

  • πŸ‡©πŸ‡ͺGermany Grevil
  • πŸ‡ΊπŸ‡¦Ukraine Matroskeen πŸ‡ΊπŸ‡¦ Ukraine, Lutsk

    If we'll look into \Drupal\taxonomy\Entity\Term and @ContentEntityType annotation, we'll see that canonical link exists by default:

    *   links = {
     *     "canonical" = "/taxonomy/term/{taxonomy_term}",
     *     "delete-form" = "/taxonomy/term/{taxonomy_term}/delete",
     *     "edit-form" = "/taxonomy/term/{taxonomy_term}/edit",
     *     "create" = "/taxonomy/term",
     *   },
    

    We also have proof in the functional tests that "Taxonomy" is available in the supported entity types:

    $this->drupalGet('admin/config/content/rabbit-hole');
    $this->assertSession()->fieldExists('entity_types[user]');
    $this->assertSession()->fieldExists('entity_types[node]');
    $this->assertSession()->fieldExists('entity_types[taxonomy_term]');
    

    After that, I noticed this in rabbit_hole_href.module. No surprise it's not working - canonical link for taxonomy terms is not available anymore:

    function rabbit_hole_href_entity_type_alter(array &$entity_types) {
      // @todo Determine the entity types which have rabbit_hole_href enabled as
      // rh_action, see Drupal\rabbit_hole\BehaviorInvoker, and go through them
      // instead of only taxonomy_term:
      // behaviourInvorker->getRabbitHoleValuesForEntityType($entity_type, $bundle);
      // NOTE: Currently the uri callback is always set, even if redirect is set to
      // 404 etc.!!
      $entity_types['taxonomy_term']->setUriCallback('rabbit_hole_href_redirect_uri');
      $links = $entity_types['taxonomy_term']->get('links');
      unset($links['canonical']);
      $entity_types['taxonomy_term']->set('links', $links);
    }
    

    Maybe the unset is not necessary? For example, in one of the core modules this is not happening:

    /**
     * Implements hook_entity_bundle_info_alter().
     */
    function forum_entity_bundle_info_alter(&$bundles) {
      // Take over URI construction for taxonomy terms that are forums.
      if ($vid = \Drupal::config('forum.settings')->get('vocabulary')) {
        if (isset($bundles['taxonomy_term'][$vid])) {
          $bundles['taxonomy_term'][$vid]['uri_callback'] = 'forum_uri';
        }
      }
    }
    

    Let me know if you think that conditions in Rabbit Hole should be different.

  • Status changed to Closed: works as designed 12 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    @Matroskeen, thank you! I thought, I'd tested this without rabbit_hole_href enabled! My apologies, I probably forgot to clear all caches, after I uninstalled it...

    And thanks for the example from core! I couldn't properly solve this inside πŸ› Using this module in Drupal 10 currently breaks the module Active yesterday, as it is currently broken for the newest Drupal version anyway.

Production build 0.69.0 2024