Invalid context for call to FieldDefinitionInterface->isDisplayConfigurable()

Created on 28 June 2023, about 2 years ago
Updated 23 October 2023, almost 2 years ago

Problem/Motivation

I'm using this module on a site where I am also using the Computed Field module. This caused a whitescreen when displaying my first computed field.

Steps to reproduce

Enable Field Permissions module. Create a Computed Field (there's a reverse entity reference plugin built-in -- if you create an entity reference to your bundle from somewhere, this will work)

Add your computed field to a display mode rendering the target entity.

Create content appropriate to make something display.

View the entity with the Computed field.

Proposed resolution

The problem is triggered by Computed Field's strict implementation of `FieldDefinitionInterface->isDisplayConfigurable()` in `src/Entity/ComputedField.php`. It uses a `match()` to decide on a response. The documentation for FieldDefinitionInterface states that only "view" or "form" are valid values for the $display_context variable, and the match() statement only accounts for these.

  /**
   * Returns whether the display for the field can be configured.
   *
   * @param string $display_context
   *   The display context. Either 'view' or 'form'.
   *
   * @return bool
   *   TRUE if the display for this field is configurable in the given context.
   *   If TRUE, the display options returned by getDisplayOptions() may be
   *   overridden via the respective entity display.
   *
   * @see \Drupal\Core\Entity\Display\EntityDisplayInterface
   */
  public function isDisplayConfigurable($display_context);

However, field_permissions alters the context argument before invoking `->isDisplayConfigurable($context)` by specifically replacing values of "view" with "display". That violates the specification for isDisplayConfigurable().

You can see the strange code here. The git history does not make it clear to me why this is being done.

I assume this works in most cases because other implementations of isDisplayConfigurable() are less picky, but I suspect this may also be producing a lot of php warnings.

Remaining tasks

I'll submit a patch as I believe it's a pretty simple change, but confirmation on this change from module experts would be helpful since it's clearly a very deliberate piece of code. I just can't figure out .

Related issue on Computed Field is #3369317 πŸ› Incompatible with Field Permissions module Closed: works as designed

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States gcb

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

Comments & Activities

Production build 0.71.5 2024