How to use term edit page instead of view page?

by vijaycs85   Last Updated August 13, 2019 17:07 PM

On the terms list page, each term is linked to the view page (i.e. term/[tid]). As I don't have any details in the view page, I would like to link it to edit page. (.i.e term/[tid]/edit). How to alter this behavior?

Tags : 8 taxonomy-terms

Answers 1

There are a few ways we could achieve this:

Option 1: Introduce a route subscriber in a custom module with below code:

    $route = $collection->get('entity.taxonomy_term.edit_form');
    $collection->add('entity.taxonomy_term.canonical', $route);

This code would replace the edit_form to the canonical route.

Note: Might need to update the local task to remove the view tab as it is confusing to see the edit form in the view tab (as below).

enter image description here

Option 2: Extend Drupal\taxonomy\Form\OverviewTerms form and overwrite buildForm method and use $term->toUrl('edit-form') as below:

      $form['terms'][$key]['term'] = [
        '#prefix' => !empty($indentation) ? $this->renderer->render($indentation) : '',
        '#type' => 'link',
        '#title' => $term->getName(),
        '#url' => $term->toUrl('edit-form'),

However, it might not be a good idea considering how complex buildForm method is and the effort to keep up with any core changes.

August 13, 2019 16:53 PM

Related Questions

Updated July 08, 2017 09:07 AM

Updated November 09, 2017 22:07 PM

Updated May 03, 2018 08:07 AM

Updated August 18, 2017 10:07 AM