Quick Edit: Check if entity is null in hook_preprocess_field

Created on 8 November 2024, about 1 month ago

Problem/Motivation

In the file quickedit.module, hook_preprocess_field, if $entity is NULL the module display the typical "The website encountered an error" page because it is calling the function getFieldDefinition on null.

Steps to reproduce

It is really dificult to replicate:

I have a field of type 'link', multiple. 2 of these links are links to public files, 1 is failing.

Proposed resolution

Instead of displaying an error , we could check if $entity is NULL as part of the first check.

Current:

if (!\Drupal::currentUser()->hasPermission('access in-place editing') || ($entity instanceof RevisionableInterface && !$entity->isLatestRevision())) {
    return;
  }

Update:

if (!\Drupal::currentUser()->hasPermission('access in-place editing') || empty($entity) || ($entity instanceof RevisionableInterface && !$entity->isLatestRevision())) {
    return;
  }

In this way, quickedit 'fail' gracefully instead of breaking the page

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇪🇸Spain dioni

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024