Set Label runs two times on node creation

Created on 21 August 2019, almost 5 years ago
Updated 23 June 2024, 5 days ago

Hello,

When creating a new node function setLabel() will be executed two times. First in hook_entity_presave() and after in hook_entity_insert().
Inside automatic entity label i got a custom token which returns an incresing number. When setLabel runs two times my custom token will be executed two times which is a problem to me.
My question is , which is the main purpose of hook_enity_insert function, because if i delete it , everything works like a charm.

Thank you.

🐛 Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

🇬🇷Greece Orestis Nerantzis Thessaloniki

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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.

  • 🇺🇸United States euk

    Attaching a refactored patch to address the following:

    - coding standards (I hope I caught all of them),
    - added the missing AutoEntityLabelManager class reference,
    - re-rolled the patch against 3.x (it was something below 3.x it and was not applying),
    - fixed issue with info.yml file - the patch would not apply due to presence of the auto-generated package information.

    This patch applied cleanly and looks like it fixed our issue with duplicate aliases - since we don't rely on any funky tokens, this should work in our situation.

  • 🇺🇸United States euk
  • 🇺🇸United States euk

    Well, what do you know - it is failing here due to info.yml again. Attaching same file with a slight change around that hunk.

  • 🇺🇸United States euk

    Last attempt...

  • 🇦🇺Australia VladimirAus Brisbane, Australia

    Creating MR instead of patches.
    Make sure to push your changes to MR. 🎉

  • Status changed to Needs review over 1 year ago
  • 🇦🇺Australia VladimirAus Brisbane, Australia

    Applied patch #77 to MR with few extra coding standards.

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States SocialNicheGuru

    No longer applies to 3.0 version

  • 🇦🇺Australia VladimirAus Brisbane, Australia

    @SocialNicheGuru did you use diff from MR?

  • Status changed to Needs review over 1 year ago
  • 🇦🇺Australia VladimirAus Brisbane, Australia

    All works for me

      - Installing drupal/auto_entitylabel (3.0.0): Cloning 8.x-3.0 from cache
      - Applying patches for drupal/auto_entitylabel
        https://git.drupalcode.org/project/auto_entitylabel/-/merge_requests/10.diff (Set Label runs two times on node creation https://www.drupal.org/project/auto_entitylabel/issues/3076302)
    
  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States euk

    From what I understand, at least locally (with Composer), when it comes to info.yml file failing the patch - it looks like it conflicts with the lines auto-generated by DO packaging script. However, I was able to figure out a workaround - just adding an extra context line... IDK

  • First commit to issue fork.
  • 🇺🇸United States SocialNicheGuru

    the MR does not apply to 3.0.

    - Installing drupal/auto_entitylabel (3.0.0): Extracting archive
    - Applying patches for drupal/auto_entitylabel
    https://git.drupalcode.org/project/auto_entitylabel/-/merge_requests/10.... (Set Label runs two times on node creation - https://www.drupal.org/project/auto_entitylabel/issues/3076302 🐛 Set Label runs two times on node creation Needs work )
    Could not apply patch! Skipping. The error was: Cannot apply patch https://git.drupalcode.org/project/auto_entitylabel/-/merge_requests/10....

  • 🇺🇸United States msielski

    To apply the diff (from the MR) with a composer install, #84 is correct you just need one more blank line of context. I'm not sure how to adjust this so it works for non-composer and composer installs, but my updated patch is attached and applies to 3.0.0. I am skipping submitting this change to the MR since it would break the patch for non-composer users. Anyone who knows the best way to handle this problem (I've seen it before with patching info.yml files) please let us know.

  • 🇮🇳India vikas shishodia

    Hi,
    I am using 3.0.0 version of 'Entity Auto Label' module. With this version i am facing issue with content moderation, when I create a content first time in Draft state it does not reflect in Moderated Content tab. However if I resave that content then it start reflecting in Moderated content tab.

    To fix this I used the Re roll patch provided in https://www.drupal.org/project/auto_entitylabel/issues/3076302#comment-1... 🐛 Set Label runs two times on node creation Needs work Using this patch my issue got resolved.

    But now when I am creating node first time then it is invoking hook_entity_insert, that is fine. But it also invoking hook_entity_update due to which, the code that i only want to run on node update is also triggering at the node create issue.

    So to fix both the above mentioned issue, I just use the 3.0.0 version and removed the hook_entity_insert() from module file then my both use cases are working perfectly.

    So need to verify is there any issue if I remove hook_entity_insert() for module file from module 3.0.0 version? Please clarify.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 7.3 & MySQL 8
    last update 5 days ago
    Composer error. Unable to continue.
  • Status changed to Needs review 5 days ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 7.3 & MySQL 8
    last update 5 days ago
    Patch Failed to Apply
  • 🇦🇺Australia VladimirAus Brisbane, Australia

    Resolved conflicts.

Production build 0.69.0 2024