Render error with Layout Builder

Created on 31 July 2024, 8 months ago

Problem/Motivation

Use the layout builder. Render with linked field and use the link from a url field.

Steps to reproduce

Use the layout builder. Render with linked field and use the link from a url field.

The website encountered an unexpected error. Try again later.

TypeError: Cannot access offset of type array on array in Drupal\Core\Entity\ContentEntityBase->get() (line 596 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Drupal\linked_field\LinkedFieldManager->getDestination('field', Array, Array) (Line: 361)
linked_field_entity_display_build_alter(Array, Array, NULL) (Line: 552)
Drupal\Core\Extension\ModuleHandler->alter('entity_display_build', Array, Array, NULL) (Line: 88)
Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler->alter('entity_display_build', Array, Array) (Line: 289)
Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 282)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple(Array) (Line: 226)
Drupal\Core\Entity\Entity\EntityViewDisplay->build(Object) (Line: 461)
Drupal\Core\Entity\EntityViewBuilder->viewField(Object, Array) (Line: 243)
Drupal\Core\Field\FieldItemList->view(Array) (Line: 167)
Drupal\layout_builder\Plugin\Block\FieldBlock->build() (Line: 106)
Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray->onBuildRender(Object, 'section_component.build.render_array', Object)
call_user_func(Array, Object, 'section_component.build.render_array', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'section_component.build.render_array') (Line: 90)
Drupal\layout_builder\SectionComponent->toRenderArray(Array, 1) (Line: 88)
Drupal\layout_builder\Section->toRenderArray(Array, 1) (Line: 228)
Drupal\layout_builder\Element\LayoutBuilder->buildAdministrativeSection(Object, 0) (Line: 112)
Drupal\layout_builder\Element\LayoutBuilder->layout(Object) (Line: 86)
Drupal\layout_builder\Element\LayoutBuilder->preRender(Array)
call_user_func_array(Array, Array) (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725 β†’ ', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 870)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 432)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 504)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 263)
Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 130)
Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

Details pending.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.5

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia interlated

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

Merge Requests

Comments & Activities

  • Issue created by @interlated
  • πŸ‡¦πŸ‡ΊAustralia interlated
  • πŸ‡¦πŸ‡ΊAustralia interlated

    Basic fix to check for an array. Just this

    $destination_src = $settings['destination'] ?? FALSE;
        if (is_array($destination_src)) {
          $destination_src = $destination_src['field'];
        }
    

    2 thoughts

    - is there a more 'api' driven approach rather than pulling destination off the settings array?
    - apply a type check to $manager->getDestination to ensure that the field name is a string?

  • Status changed to Needs review 6 months ago
  • πŸ‡¦πŸ‡ΊAustralia interlated
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Please test πŸ› Special characters are stripped Needs review to see if it resolves the problem.

  • Pipeline finished with Success
    6 months ago
    Total: 140s
    #301550
  • πŸ‡¦πŸ‡ΊAustralia interlated

    No - didn't fix the problem. Complaint is that there is an array in an array

    - removed patched linked_field
    - installed from composer
    - cache reset
    - Fuss around as the config didn't seem to load
    - Edit the display in layout builder (there are multiple view-modes)
    - Error
    - Apply patch
    - Cache reset
    - Error

    The website encountered an unexpected error. Try again later.

    TypeError: Cannot access offset of type array on array in Drupal\Core\Entity\ContentEntityBase->get() (line 596 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
    Drupal\linked_field\LinkedFieldManager->getDestination('field', Array, Array) (Line: 361)
    linked_field_entity_display_build_alter(Array, Array, NULL) (Line: 552)
    Drupal\Core\Extension\ModuleHandler->alter('entity_display_build', Array, Array) (Line: 289)
    Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 282)
    Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple(Array) (Line: 226)
    Drupal\Core\Entity\Entity\EntityViewDisplay->build(Object) (Line: 461)
    Drupal\Core\Entity\EntityViewBuilder->viewField(Object, Array) (Line: 243)
    Drupal\Core\Field\FieldItemList->view(Array) (Line: 167)
    Drupal\layout_builder\Plugin\Block\FieldBlock->build() (Line: 106)
    Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray->onBuildRender(Object, 'section_component.build.render_array', Object)
    call_user_func(Array, Object, 'section_component.build.render_array', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'section_component.build.render_array') (Line: 90)
    Drupal\layout_builder\SectionComponent->toRenderArray(Array, 1) (Line: 88)
    Drupal\layout_builder\Section->toRenderArray(Array, 1) (Line: 228)
    Drupal\layout_builder\Element\LayoutBuilder->buildAdministrativeSection(Object, 0) (Line: 112)
    Drupal\layout_builder\Element\LayoutBuilder->layout(Object) (Line: 86)
    Drupal\layout_builder\Element\LayoutBuilder->preRender(Array)
    call_user_func_array(Array, Array) (Line: 113)
    Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725 β†’ ', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 870)
    Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 432)
    Drupal\Core\Render\Renderer->doRender(Array) (Line: 504)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
    Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
    call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 263)
    Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 130)
    Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

  • πŸ‡¦πŸ‡ΊAustralia interlated

    I have 2 more issues I haven't resolved with linked_field.

    - Advanced attributes field isn't long enough. I can't see how to alter third-party-settings form

    e.g. this is what I want to put in there

    $variables['items'][0]['content']['#options']['attributes']['data-dialog-options'][] = '{"width":"80vw","height":"100%", "dialogClass": "course-dialog", "position": {"my": "right top", "at": "right top"}, "show":"slideDown","hide":"slideUp"}';

    - tokens don't resolve with layout builder. I debugged the call to resolve token and I get 'value['node'] which I think is fine. Token is [field_course_info_link:uri]

Production build 0.71.5 2024