Title is still showing up in layout builder despite settings

Created on 3 July 2019, over 5 years ago
Updated 15 August 2024, 3 months ago

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

πŸ› Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom QuietSpecialist

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

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States galactus86

    Hello.

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

    I am on Drupal core 9.5.3

  • πŸ‡ΊπŸ‡ΈUnited States codechefmarc

    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.

  • Status changed to Needs work about 1 year ago
  • πŸ‡¨πŸ‡¦Canada megan_m

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

  • Status changed to Needs review 10 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 7.3 & MySQL 8
    last update 10 months ago
    Composer error. Unable to continue.
  • πŸ‡«πŸ‡·France simon georges Rouen, France

    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 ;-)

  • πŸ‡ΊπŸ‡ΈUnited States codechefmarc

    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.

  • Status changed to Needs work 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States SocialNicheGuru
  • πŸ‡«πŸ‡·France simon georges Rouen, France

    @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!

  • πŸ‡«πŸ‡·France xavier.masson Haute-Normandie

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

    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);
    
  • πŸ‡ΊπŸ‡ΈUnited States codechefmarc

    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:




    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-...

  • πŸ‡«πŸ‡·France xavier.masson Haute-Normandie

    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.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • πŸ‡ΊπŸ‡ΈUnited States SocialNicheGuru

    Reroll of patch #17 for auto_entitylabel 3.3.0

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

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

  • πŸ‡©πŸ‡ͺGermany hctom

    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?

Production build 0.71.5 2024