Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Taxonomy Custom Controller

139 sites Security covered Drupal 9–11
View on drupal.org

This module allows you to customize taxonomy term pages. You can alter the content of these pages for specific vocabularies or terms by subscribing to events and writing custom code.

The Taxonomy Custom Controller module is a default Taxonomy Term entity canonical controller override with event.

It will help you to subscribe to event and change content of term page. You can change it for specific vocabularies, or specific term with conditions you want!

USAGE

Simple example:

/**
 * Provides subscriber for term page build.
 */
class TermPageBuildSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      TaxonomyCustomControllerEvents::PAGE_BUILD => 'onTermPageBuild',
    ];
  }

  /**
   * Reacts on term page build.
   *
   * @param \Drupal\taxonomy_custom_controller\Event\TermPageBuildEvent $event
   *   The event.
   */
  public function onTermPageBuild(TermPageBuildEvent $event) {
    $taxonomy_term = $event->getTaxonomyTerm();
    if ($taxonomy_term->bundle() != 'tags') {
      return;
    }

    // Adds term description on top of the default views.
    $build = [];
    if (!$taxonomy_term->get('description')->isEmpty()) {
      $build['description'] = [
        '#type' => 'container',
        '#attributes' => [
          'class' => ['wrapper-for-custom-added-description'],
        ],
        'description' => $taxonomy_term->get('description')->view(),
      ];
    }
    $build['view'] = views_embed_view('taxonomy_term', 'page_1', $taxonomy_term->id());
    $event->setBuildArray($build);
  }

}

See taxonomy_custom_controller_example module for full example.

SIMILAR PROJECTS

  • TVI — does the same thing. The main difference. With TVI you can use only Views and configure it via UI. With TCC you can do whatever you want, but you need to write Event Subscriber.

Depends on

Dependencies of the latest stable release

  • taxonomy Drupal core
  • views Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Jan 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Core Release date
8.x-1.6 Stable 9–11 Jan 28, 2025