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

Issue fork diff-3204468

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Mingsong created an issue. See original summary.

mingsong’s picture

StatusFileSize
new945 bytes

Patch to fix this issue.

mingsong’s picture

Issue summary: View changes
mingsong’s picture

Issue summary: View changes
adriancid’s picture

Status: Active » Reviewed & tested by the community

I'm facing the same issue and this patch fixed the problem.

sander wemagine’s picture

Tested patch and is working for me.

I had another error, but this patch fixes this error.
TypeError: Unsupported operand types: null + array in template_preprocess_links() (line 674 of core/includes/theme.inc).
I am using the diff module on a custom entity without view modes, this was leading to this bug.

acbramley’s picture

Version: 8.x-1.0 » 8.x-1.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Thanks for the work on this one. I've recently taken up maintainership of this project and am looking through the RTBC issues.

To get this in, I'll need the MR rebased against the latest 8.x-1.x as well as a test case showing the bug is fixed

Thanks!

mingsong’s picture

Thanks @Adam,

I just rebased the MR and will be working on test when I have a chance.

codebymikey’s picture

Priority: Normal » Major
Related issues: +#3524811: Integrate revision diff support and ability to enable revision creation by default
StatusFileSize
new1.02 KB

Ran into this issue whilst working on integrating sitewide_alert with the diff module on #3524811: Integrate revision diff support and ability to enable revision creation by default as it doesn't use any view modes.

The patch within this issue fixes the fatal TypeError as referenced in #7.

acbramley’s picture

Status: Needs work » Postponed (maintainer needs more info)

I think this will be entirely solved by #2452523: Offer a revisions tab for all entities - it contains changes to the VisualInlineDiffLayout class to handle empty view modes. It also provides entity type agnostic diff functionality.

Can someone please verify this and close this issue if it does. Thanks!

codebymikey’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Yup, can confirm that #2452523: Offer a revisions tab for all entities essentially solves this from doing a quick test.

Needed to add this commit though in order to stop it from passing a NULL value as the view_mode.

Until that's been merged, the patch in this issue is an easy fix to avoid the crash. So closing, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

codebymikey’s picture