Layout builder warning: Field failed to render with error of ""

Created on 16 March 2023, over 1 year ago
Updated 11 October 2023, about 1 year ago

I'm using an editable field (list text) via layout manager and when a user triggers a field update, three things happen:
- the value is updated
- an uncaught AJAX HTTP error occurrs
- a watchdog entry is created by layout_builder: field failed to render with the error of ""

I've tried several config adjustments but to no avail. I just seem to not grasp why this is happening.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany Rudi Teschner

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

Comments & Activities

  • Issue created by @Rudi Teschner
  • 🇩🇪Germany Rudi Teschner

    I don't know the reason why it happens yet. But I've found a workaround by patching core for fields related to this module.

    If the exception handling is removed for fields related to this module it does the trick - no exceptions thrown. Though I don't know why the exception handling causes the problems though - or rather brings the problems to light?

    diff --git a/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php b/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php
    index 4318ebee24..4d3fe0a698 100644
    --- a/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php
    +++ b/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php
    @@ -160,21 +160,32 @@ public function build() {
         $display_settings = $this->getConfiguration()['formatter'];
         $display_settings['third_party_settings']['layout_builder']['view_mode'] = $this->getContextValue('view_mode');
         $entity = $this->getEntity();
    -    try {
    +    
    +    if ($display_settings['type'] == 'editablefields_formatter') {
           $build = [];
           $view = $entity->get($this->fieldName)->view($display_settings);
           if ($view) {
             $build = [$view];
           }
         }
    -    // @todo Remove in https://www.drupal.org/project/drupal/issues/2367555.
    -    catch (EnforcedResponseException $e) {
    -      throw $e;
    -    }
    -    catch (\Exception $e) {
    -      $build = [];
    -      $this->logger->warning('The field "%field" failed to render with the error of "%error".', ['%field' => $this->fieldName, '%error' => $e->getMessage()]);
    +    else {
    +      try {
    +        $build = [];
    +        $view = $entity->get($this->fieldName)->view($display_settings);
    +        if ($view) {
    +          $build = [$view];
    +        }
    +      }
    +        // @todo Remove in https://www.drupal.org/project/drupal/issues/2367555.
    +      catch (EnforcedResponseException $e) {
    +        throw $e;
    +      }
    +      catch (\Exception $e) {
    +        $build = [];
    +        $this->logger->warning('The field "%field" failed to render with the error of "%error".', ['%field' => $this->fieldName, '%error' => $e->getMessage()]);
    +      }
         }
    +    
         CacheableMetadata::createFromRenderArray($build)->addCacheableDependency($this)->applyTo($build);
         return $build;
       }
    
Production build 0.71.5 2024