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?
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).
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.