%AutoEntityLabel% title when "Preserve already created node titles." option is enabled

Created on 29 September 2021, over 2 years ago
Updated 3 June 2024, 23 days ago

I get always %AutoEntityLabel% title after creation content.

How to recreate it:

1. Create content type.
2. Set "Automatic label generation" option to "Automatically generate the label and hide the label field".
3. Set "Pattern for the label" to "[current-date:raw] - [random:number]".
4. Disable "Remove special characters." option.
5. Enable "Preserve already created node titles." option.
6. Disable "Re-save" option.
7. Create a new content and you'll get %AutoEntityLabel% for the title.

The problem is when you disable "Preserve already created node titles." option AutoEntityLabelManager::setLabel isn't called either on insert or preserve hooks.

🐛 Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

🇺🇦Ukraine lobodacyril

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 greenSkin

    Here's an alternate patch that moves the "isTitlePreserved()" check into the "autoLabelNeeded()" method and ignores preserving the title if the title is empty or is "%AutoEntityLabel%".

  • Status changed to RTBC over 1 year ago
  • 🇮🇳India Meeni_Dhobale

    Hello,
    I reviewed the patch #21 and it's working fine for me. I also check with the other two options, Remove special characters and Re-save. This patch is working fine so issue can be move to RTBC.

  • Status changed to Needs work over 1 year ago
  • Hi,

    I am still experiencing the same issue as described in #6 and #7 so not sure if this should be RTC.

  • Status changed to Needs review over 1 year ago
  • 🇺🇸United States greenSkin

    Here's an update for patch from #21 that checks the entity ID is not empty when determining if generating the auto label is needed, i.e., if empty ID then auto label is not needed (don't auto-generate label).

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States DamienMcKenna NH, USA

    #24 seems to not work correctly on newly created entities when the "Automatically generate the label and hide the label field" option is set, it creates entities with empty labels. This can be seen by the tests failing.

  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States DamienMcKenna NH, USA

    A variation of #24 that includes this change:

    @@ -161,8 +161,7 @@ function auto_entitylabel_entity_presave(EntityInterface $entity) {
         $decorator = \Drupal::service('auto_entitylabel.entity_decorator');
         /** @var \Drupal\auto_entitylabel\AutoEntityLabelManager $decorated_entity */
         $decorated_entity = $decorator->decorate($entity);
    -    if ($decorated_entity->hasLabel() && $decorated_entity->autoLabelNeeded()
    -      && !$decorated_entity->isTitlePreserved()) {
    +    if ($decorated_entity->autoLabelNeeded()) {
           $decorated_entity->setLabel();
         }
       }
    
  • 🇺🇸United States DamienMcKenna NH, USA

    Forgot a second part of the fix.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States DamienMcKenna NH, USA

    Clearly this needs some more work.

  • 🇺🇸United States DamienMcKenna NH, USA

    I opened 🐛 Generate+Hide option fails when Preserve Title option selected Needs review for a similar problem creating nodes when the "Preserve" option is enabled; it might ultimately be same bug, but I thought cleanly starting with test coverage would be a good approach.

  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States DamienMcKenna NH, USA

    I did not realize that setLabel() threw an exception if the entity didn't allow labels.

  • Status changed to Needs work 8 months ago
  • 🇦🇺Australia jannakha Brisbane!

    - needs to pass tests
    - the patch doesn't apply tokens, eg [node:nid] is not being added to the label if it's part of the auto label template

  • 🇩🇪Germany Anybody Porta Westfalica

    I can also confirm this issue, resulting in "" when using that option

    Please also note the remarkable work done by @DamienMcKenna in 🐛 Generate+Hide option fails when Preserve Title option selected Needs review regarding tests. Should we eventually combine the changes in one issue and MR?

  • 🇩🇪Germany Anybody Porta Westfalica
Production build 0.69.0 2024