Hi,

Currently the module doesn't appear to integrate with the Layout Builder module i.e. I can still see the title field despite setting the Automatic label generation for hero field to Automatically generate the label and hide the label field.

Here I'm assuming the title field in layout builder is the block label (screenshot attached).

Drupal version 8.7.3

EDIT: This may also be a bug with the Layout Builder and not a feature request for this module.

Thanks,

S

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

digitaldots created an issue. See original summary.

QuietSpecialist’s picture

Title: Integration with layout builder for custom block types » Integration with Layout Builder for custom block types
Issue summary: View changes
colan’s picture

Version: 8.x-2.1-beta1 » 8.x-3.x-dev
Status: Active » Postponed (maintainer needs more info)

Is this still a problem in the latest dev branch?

QuietSpecialist’s picture

Hi,

I'll take a look this weekend.

joele75’s picture

Can confirm the title field still displays using latest dev branch when adding/editing an inline custom block type in Layout Builder.

Drupal version 8.76

chris burge’s picture

Status: Postponed (maintainer needs more info) » Active

Yes, this is still an issue with Drupal Core 8.7.6 and Auto Entity Label 8.x-3.0-dev. When adding an inline block, the Title field is unaffected by Auto Entity Label.

Extending to Auto Entity Label to support Layout Builder should be pretty straightforward. Take a look at https://www.drupal.org/project/inline_block_title_automatic.

chris burge’s picture

Assigned: Unassigned » chris burge
chris burge’s picture

Every block has a 'Block description', which can be thought of as an admin title. This is the value that Automatic Entity Label currently modifies. (The block description is not editable from Layout Builder.)

When we work in Layout Builder, every element is placed as a component. Each component has its own attributes, which include a component title. In the case where a block is placed in Layout Builder, the component title belongs to the component, not to the block. The component title is the subject of this issue.

The issue requests to extend Automatic Entity Label to modify component labels belonging to blocks placed in Layout Builder in addition to overriding their block descriptions.

chris burge’s picture

Assigned: chris burge » Unassigned
StatusFileSize
new4.14 KB

We've decided to go another direction with our project; however, I'm attaching a patch of my work thus far in case someone else wants to take this up.

The attached patch implements the UI (hiding/showing the component title on Layout Builder forms). It doesn't store the auto label for the Layout Builder component. That part still needs written.

colan’s picture

Status: Active » Needs work

Updating status. Thanks for this!

aarnau’s picture

StatusFileSize
new4.12 KB

Hello, applying the patch I have obtained the following notice: Undefined variable: layout_builder_form in auto_entitylabel_prepare_entityform() (line 204 of modules/contrib/auto_entitylabel/auto_entitylabel.module)
I have rebuilt the patch so it doesn't report the notice.

colan’s picture

#11: Please provide interdiffs when posting patches.

nwom’s picture

This would be amazing to have, since it would replace the need for Inline Block Title Automatic and allow you to automatically create a description like "PARENT NODE TITLE - BLOCK TYPE" which would be alot more descriptive than what is currently possible in the aforementioned module. The other advantage is that displaying the title would be configurable, whereas the other module always hides the label.

andyg5000’s picture

andyg5000’s picture

StatusFileSize
new7.83 KB

Here's the requested interdiff from #9-#11

andyg5000’s picture

Status: Needs work » Needs review
StatusFileSize
new440 bytes
new4.15 KB

Here's a fix to #14 rolling with the changes in #11.

gromani14’s picture

Patch is not working... just re-rolled the same patch. (looks like a commit 6 month ago added a line on the uses section)

galactus86’s picture

Hello.

I just applied the patch from #17 and it seems to be working fine.

I am on Drupal core 9.5.3

codechefmarc’s picture

Strange - I'm trying the patch in #17 and anything I put into the "Pattern for the label" field gets replaced with ""%AutoEntityLabel%" block" and not the text I specified. I tried using both regular text and a token replacement.

megan_m’s picture

Status: Needs review » Needs work
StatusFileSize
new18.65 KB

The ""%AutoEntityLabel%" block" text is appearing for me only in Layout builder. It's not displayed on the front-end.

Screenshot showing the "%AutoEntityLabel%" text in Layout builder

simon georges’s picture

Status: Needs work » Needs review
StatusFileSize
new4.15 KB
new555 bytes

In my case, the patch in #17 was allowing the prepare_form to execute for Inline Blocks, but the form was not actually correctly prepared. Fix the attached fix, it works for me... Let's hope it's the case for all of you as well ;-)

codechefmarc’s picture

I just tried your patch, Simon, and it worked for me but only in the /admin/content/block area. It didn't work for me for when you're adding blocks inline inside layout builder itself.

I tried #17 as well and it only sort of works for me - the default value for the admin label isn't getting set appropriately. I'm using the "Automatically generate the label if the label field is left empty". It will set the value correctly in the DB, but not in the admin label field, so (for example we have an Accordion block) it will put the block name in the field instead of what we put as the auto label, so it will put "Accordion". I think I found a fix for this, but, the preview text doesn't work yet, so I'm still working through that piece.

socialnicheguru’s picture

Status: Needs review » Needs work
simon georges’s picture

@codechefmarc, the patch works for me in the Layout Builder as well, so I'm wondering what contrib module I have that could alter this... I'll check back at work this week, thanks for your feedback!

xavier.masson’s picture

I agree with @codechefmarc patch #21 doesn't work for me but #17 does within the layout builder.

The block form is generated from core/lib/Drupal/Core/Block/BlockPluginTrait.php line 173 :

    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Title'),
      '#maxlength' => 255,
      '#default_value' => $this->label(),
      '#required' => TRUE,
    ];

the interdiff between 17-21 merge oldly the $widget['value'] directly within the label (textfield form element) but after the #20 patch it was applied to nested elements as $form['settings']['label']['value].

-      $form['settings']['label'] = array_merge($form['settings']['label'], $widget['value']);
+     $form['settings']['label'] = array_merge($form['settings']['label'], $widget);
codechefmarc’s picture

I've started some work in an MR - it's not ready yet as it still has some problems, but I based it off of #17 and started adding some things of my own. Mainly, once someone adds a block with auto_entitylabel, it was saving the correct auto label in the database, but not setting that as the block administrative title. So, I added some code to the auto_entitylabel_prepare_entityform function that still gets a decorated entity but splits that into its own variable. Then, we can use the passed in $entity to get a default value (I'm specifically testing for the case AutoEntityLabelManager::OPTIONAL:.

This works ... sort of. You have to save the block twice for it to actually take in the UI when not previewing the content and instead layout builder only shows the administrative titles. See new screenshots:

Initial add block
After initial save of block
After save node, then edit block
After second save

So, what I think needs to be done is to play with the auto_entitylabel_entity_prepare_view and/or auto_entitylabel_entity_presave functions to make sure it's saving the admin title so layout builder can read it correctly? I'm not as well versed with the entity API, so I'm running a little bit out of my comfort zone but I'll still press on to see what else I can do.

As a second issue here, if I choose to hide the label field and auto generate, I get the %AutoEntityLabel% as previously reported. That's, I think, being provided on line 185 (in my MR below) so that's something separate to troubleshoot.

See here for my current changes (Note again, this is not ready for merging yet):
https://git.drupalcode.org/issue/auto_entitylabel-3065687/-/compare/8.x-...

xavier.masson’s picture

In case we are in the Layout builder form does the label value must be directly generated for the AutoEntityLabelManager::ENABLED to avoid to have %AutoEntityLabel% displayed until to save the layout builder and invoke auto_entitylabel_entity_presave?

Like below :

case AutoEntityLabelManager::ENABLED:
        ...
        if (!empty($layout_builder_form)) {
          $widget['value']['#default_value'] = $entity->setLabel();
          $form['settings']['label_display']['#default_value'] = FALSE;
          $form['settings']['label_display']['#type'] = 'value';
        }
        break;

@codechefmarc i'll try to give a try to your work in progress to give some feedbacks.

anybody’s picture

socialnicheguru’s picture

Reroll of patch #17 for auto_entitylabel 3.3.0

anybody’s picture

Title: Integration with Layout Builder for custom block types » Title is still showing up in layout builder despite settings
Category: Feature request » Bug report
Priority: Normal » Minor

Relabeled as a bug in combination with layout builder. As a workaround you can maybe just remove the title block in layout builder?

hctom’s picture

I just checked the patch from #29 with Drupal 10.3.2 and unfortunately it is for me also only working when creating a block content via Admin -> Content -> Blocks -> Add content block.

When using it with the "Automatically generate the label and hide the label field" setting in layout builder context with an inline block, the field is hidden as expected, but the label is always %AutoEntityLabel% (even when updating the inline block later).

I think the biggest problem here, is that for new/updated inline blocks, the auto_entitylabel_entity_presave() hook is not called directly when adding/updating the block, but when the surrounding entity's layout is saved as a whole. I debugged through the code and saw that AutoEntityLabelManager::setLabel() actually gets the correct label, but setting it on the inline block entity does not work somehow.

But in order to have the correct label immediately after adding/updating an inline block in layout builder context, maybe the label field value has to be set during validation or similar, so it is always available, even when the surrounding layout has not been saved as a whole?

micnap’s picture

Correcting an issue that was showing up when trying to add a chart from the Charts module (https://www.drupal.org/project/charts). We're getting the following error with this patch when trying to add a Charts block to layout builder if the Charts block isn't figured correctly:

"Warning: Undefined array key 1 in auto_entitylabel_form_layout_builder_add_block_alter() (line 112 of modules/contrib/auto_entitylabel/auto_entitylabel.module)."

It's complaining about block_bundle in

list($plugin_id, $block_bundle) = explode(':', $build_info['args'][3]);

As $block_bundle isn't being used anywhere, removed it from the patch.

luukyb’s picture

I had the same issue as @micnap, removing $block_bundle worked for me too.