Undefined index: full in Drupal\diff\Plugin\diff\Layout\VisualInlineDiffLayout->build()

Created on 19 March 2021, almost 4 years ago
Updated 15 April 2024, 8 months ago

Problem/Motivation

I am working on developing a diff UI plugin for Taxonomy Terms and came across an issue in which the comparison table for taxonomy term
can not be rendered.

Steps to reproduce

Create a new route in which the path is '/taxonomy/term/{taxonomy_term}/revisions/view/{left_revision}/{right_revision}/{filter}' by a custom module.

In the controller function, use following codes to build the comparison table.

 $build = $this->compareEntityRevisions($route_match, $left_revision, $right_revision, $filter);

When I access following URL:
/taxonomy/term/230/revisions/view/236/237/visual_inline

a fatal PHP error caused said:

Notice: Undefined index: full in Drupal\diff\Plugin\diff\Layout\VisualInlineDiffLayout->build() (line 159 of /usr/local/var/www/govCMS8/docroot/modules/contrib/diff/src/Plugin/diff/Layout/VisualInlineDiffLayout.php)

Proposed resolution

After debugging the codes, I am aware that this issue is caused by line 139 in /src/Plugin/diff/Layout/VisualInlineDiffLayout.php

// Get all view modes for entity type.
    $view_modes = $this->entityDisplayRepository->getViewModeOptionsByBundle($entity->getEntityTypeId(), $entity->bundle());

The problem is that there is no display mode for a taxonomy bundle by default until you go to the display setting page (/admin/structure/taxonomy/manage/{vocabulary name}/overview/display) and save the setting for this vocabulary (bundle).

So $view_modes will be null if you haven't saved the display setting for a vocabulary.

The solution could be using the default display mode for an entity bundle that hasn't had any view display configuration yet. The updated code is

 // Get all view modes for entity type.
    $view_modes = $this->entityDisplayRepository->getViewModeOptionsByBundle($entity->getEntityTypeId(), $entity->bundle());
    if (empty($view_modes)) {
      // There is no any view modes for the entity bundle specified.
      // Use the default view mode of the entity instead.
      $view_modes = $this->entityDisplayRepository->getViewModeOptions($entity->getEntityTypeId());
    }

This could happen to any entity types other than Node, not just Taxonomy Terms.

Remaining tasks

Create test script.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇦🇺Australia mingsong 🇦🇺

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024