How to add a column to taxonomy overview page?

The taxonomy overview page is not a listing of entities built with the entity list builder, and it's not a View. It's just a regular form, and that means that we can use the form_alter() hook to include additional columns.

Let's see how to add a new column named Status:

/**
 * Implements hook_form_ID_alter().
 */
function MODULE_NAME_form_taxonomy_overview_terms_alter(&$form, FormStateInterface $formState) {
  $form['terms']['#header'] = array_merge(array_slice($form['terms']['#header'], 0, 1, TRUE),
    [t('Status')],
    array_slice($form['terms']['#header'], 1, NULL, TRUE));

  foreach ($form['terms'] as &$term) {
    if (is_array($term) && !empty($term['#term'])) {
      $status['status'] = [
        '#markup' => ($term['#term']->status->value) ? t('Published') : t('Unpublished'),
        '#type' => 'item',
      ];

      $term = array_slice($term, 0, 1, TRUE) +
        $status +
        array_slice($term, 1, NULL, TRUE);
    }
  }
}

I didn't write this code myself, but since it is very useful I'm sharing it here. I found it in the Thunder's Taxonomy module.

Before altering:

Image

After altering:

Image

About the Author

Goran Nikolovski is a web and AI developer with over 10 years of expertise in PHP, Drupal, Python, JavaScript, React, and React Native. He founded this website and enjoys sharing his knowledge.