- πΊπΈ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 4:56pm 6 September 2023 - π¨π¦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 2:45pm 26 January 2024 - 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 7:17pm 26 January 2024 - π«π·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 thecase 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/orauto_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 invokeauto_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.
- πΊπΈ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 thatAutoEntityLabelManager::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?