Empty field for Drupal core Layout builder (layout_builder)

Created on 18 May 2019, over 5 years ago
Updated 18 January 2023, almost 2 years ago

With this patch, empty field is also rendered on display provided by layout_builder.

Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs work over 1 year ago
  • 🇩🇪Germany hctom

    Unfortunately this does not seem to work when Allow each content item to have its layout customized. is enabled and a per-entity layout wants to display a field with empty fields config that is not available in the default layout builder config for the an entity view mode.

    Steps to reproduce:

    • Create a node type and enable layout builder for its Full display
    • Leave the Full display completely empty (in layout builder as well as in normal field UI)
    • Enable Allow each content item to have its layout customized. for Full view mode
    • Create a node of that type
    • Use the Layout tab to add fields to the layout and add a field that is empty, configure its empty field settings and save the per-node layout
    • Check the output -> the field is not outputted with the selected empty field behavior

    If you add that field to the default layout for the Full view mode at admin/structure/types/manage/NODE_TYPE/display/full/layout, accessing node/ID throws the following error:

    TypeError: array_merge(): Argument #1 must be of type array, null given in array_merge() (line 215 of modules/contrib/empty_fields/empty_fields.module).

    Accessing node/ID/layout displays everything the correct way - with empty field fallback and without any errors.

    So, I guess there is still some work to do :(

  • 🇫🇷France andypost

    both cases from comment #30 should be added to test

  • 🇺🇸United States fskreuz

    Roll in the similar one-liner change from 3192991 🐛 Contrib module classes are overwritten Needs review since it was closed in favor of this issue.

  • 🇺🇸United States fskreuz

    Undoing #33. Misread the other issue.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 10 months ago
    1 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 10 months ago
    1 pass
  • 🇺🇦Ukraine sickness29

    Improved patch from #24 and used \Drupal\layout_builder\LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY instead.
    This way we have build and all correct third party settings depending on entity, if it has overrides.
    Also noticed test fail on D9.5, so made changes so it passes both cases. I checked locally and visually nothing changed, html output for field is the same, probably test engine method that were retrieving html changed.
    Added functional javascript test as well to make sure empty fields working for default and custom layouts on test node type.

  • Status changed to Needs review 10 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 10 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 10 months ago
    2 pass
  • 🇫🇷France andypost
    1. +++ b/empty_fields.services.yml
      @@ -2,3 +2,9 @@ services:
      +  empty_fields.event_subscriber:
      +    class: Drupal\empty_fields\EventSubscriber\EmptyFieldsSubscriber
      +    arguments: ['@plugin.manager.empty_fields']
      +    tags:
      +      - { name: event_subscriber }
      

      is needs change but for 10.2+ https://www.drupal.org/node/3357408

      let's keep it as is

    2. +++ b/src/EventSubscriber/EmptyFieldsSubscriber.php
      @@ -0,0 +1,109 @@
      +  protected $manager;
      ...
      +  public function __construct(EmptyFieldsPluginManager $empty_fields_plugin_manager) {
      +    $this->manager = $empty_fields_plugin_manager;
      

      it should use constructor promotion

    please convert patch to MR

  • 🇺🇦Ukraine sickness29

    Hi @andypost
    thank you for your comments, MR created

  • 🇮🇳India junaidpv Kannur, Kerala

    Same as #38 just in patch file format for our composer based builds to rely on.

Production build 0.71.5 2024