Problem/Motivation

When creating a view of taxonomy terms with a relationship to nodes and summary with a count, some of the summary links are incorrect:

* term name is empty
* count is empty

See the attached config file for an example.

Steps to reproduce

tbc

Not sure why this is happening for some terms but not others - need to investigate further

Proposed resolution

tbc

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

malcomio created an issue.

malcomio’s picture

I was able to work around this by implementing template_preprocess_views_view_summary

function mymodule_preprocess_views_view_summary(&$variables) {
  $view = $variables['view'];
  if ($view->id() == 'taxonomy_overview') {
    foreach ($variables['rows'] as &$row) {
      $term = $row->_entity;
      $label = $term->label();

      if (empty($row->link) || empty($row->url)) {
        // Not sure why the link is empty, but we can build it ourselves.
        $row->link = $label;
        $row->url = '/admin/content/taxonomy/' . htmlentities($label);
        $row->count = $row->num_records;
      }

      // Prevent blank counts.
      if (empty($row->count)) {
        $row->count = '0';
      }

      if (str_contains($label, '/')) {
        // Slashes break contextual filters.
        // See https://www.drupal.org/project/drupal/issues/672606.
        $row->url = '/taxonomy/term/' . $term->id();
      }
    }
  }
}