Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The current dev version of Automatic Entity Labels does not work. It breaks some contrib modules (e.g.#2832953: Automatic Entity Label broke Entity Legal ) and settings are not used to set labels on entity forms when you add or edit an entity.
Proposed resolution
The patch in this issue fixes most of these bug and implements the necessary hooks for setting automatic labels when saving entities.
Remaining tasks
Testing and reviewing by by the community.
Comment | File | Size | Author |
---|---|---|---|
#46 | auto_entity_label-2755445-46.patch | 40.91 KB | Peacog |
#46 | diff-2755445-37-46.txt | 10.37 KB | Peacog |
#37 | interdiff-2755445-36-37.txt | 851 bytes | gngn |
#37 | auto_entity_label-2755445-37.patch | 42.15 KB | gngn |
#36 | interdiff-2755445-35-36.txt | 709 bytes | gngn |
Comments
Comment #2
piyuesh23 CreditAttribution: piyuesh23 at QED42 commentedAttaching patch here.
Comment #3
piyuesh23 CreditAttribution: piyuesh23 at QED42 commentedComment #4
piyuesh23 CreditAttribution: piyuesh23 at QED42 commentedComment #6
purushotam.rai CreditAttribution: purushotam.rai at QED42 commentedComment #7
webcultist CreditAttribution: webcultist commentedThrows an error when used with the latest version of https://www.drupal.org/project/yamlform.
Comment #8
webcultist CreditAttribution: webcultist commentedComment #9
webcultist CreditAttribution: webcultist commentedSeems to be related to this Issue
Comment #10
Peacog CreditAttribution: Peacog as a volunteer commentedI have done some work on this and other aspects of the D8 port of Automatic Entity Labels. I've taken and repurposed a lot of @Sutharsan's auto_nodetitle code from https://github.com/Sutharsan/auto_nodetitle/. The attached patch works for nodes, taxonomy and other configuration entities, but there is still work to be done and it needs extensive testing.
There is a known issue with taxonomy: the Auto Label tab does not show up on the vocabulary overview page (admin/structure/taxonomy/manage/{vocabulary}/overview). The admin page does exist, however, and can be accessed at admin/structure/taxonomy/manage/{vocabulary}/auto-label. I'll raise a separate issue about that.
Comment #11
Peacog CreditAttribution: Peacog as a volunteer commentedI've improved the patch by adding an automatic label operation to the entity's list of available operations. For example, on the Content types admin page (admin/structure/types) the list of available operations for each type now includes an Automatic entity label option.
Please test the patch and report back here whether or not it works for you so that we can get it committed.
Comment #12
Peacog CreditAttribution: Peacog as a volunteer commentedSorry, there was a permissions bug in the last patch. Use this one instead.
Comment #13
VladimirAusLooks good. Works well with Taxonomies and Yaml Forms.
Comment #14
Peacog CreditAttribution: Peacog as a volunteer commentedJust fixing a typo in the issue title...
Thanks for reviewing @VladimirAus
Comment #15
SurfinSpirit CreditAttribution: SurfinSpirit at FFW commentedUsing patch from #12 with panels and page_manager modules getting this issue https://www.drupal.org/node/2828102 because 'Auto label' is added to 'page' entity type. Attaching possible fix by removing 'Auto label' for this entity type.
Comment #16
SurfinSpirit CreditAttribution: SurfinSpirit at FFW commentedAttaching new patch because of some diff export issues.
Comment #17
Peacog CreditAttribution: Peacog as a volunteer commentedThanks @SurfinSpirit. I can confirm your patch fixes the Page Manager problem. I've extended the fix to include page_variant entities too, as that didn't work either.
Comment #18
SurfinSpirit CreditAttribution: SurfinSpirit at FFW commentedJust noticed that 'admin/config/content/entity_browser' gives the same error, looks like the if statement in 'auto_entitylabel_entity_type_alter' needs improvements.
Comment #19
Peacog CreditAttribution: Peacog as a volunteer commentedThinking about it some more, I think the right way to do it is to have Auto Entity Label handle only core config entities. It should also provide a hook so that any contrib modules that want to use automatic labels can hook into it. There shouldn't be any hard-coded references to contrib providers in auto_entitylabel_entity_type_alter, so we should remove the specific handling of Page Manager added in the last patch. I'll open a new issue about providing a hook for contrib modules to use.
Comment #20
Peacog CreditAttribution: Peacog as a volunteer commentedOK, I've updated the patch to work with core entity types only. I've opened a separate issue about providing a hook or service for contrib or custom modules that want to have automatic labels: #2829571: Provide a hook for contrib modules that want to implement automatic labels
Comment #21
Peacog CreditAttribution: Peacog as a volunteer commentedComment #22
Peacog CreditAttribution: Peacog as a volunteer commentedA comment posted over here #2829571: Provide a hook for contrib modules that want to implement automatic labels reported another bug that surfaces for some contrib module. I've amended the patch to include a fix.
Comment #23
Smith76 CreditAttribution: Smith76 commentedThe new patch works well with the "Profile" module.
I'll let you know if I have any other problems.
Thank you for the good work.
Comment #24
Peacog CreditAttribution: Peacog as a volunteer commentedComment #25
FeyP CreditAttribution: FeyP at werk21 commentedThanks for the patch, it seems to work well for us so far. I just noticed one issue regarding the token browser:
This works, if the token type is the same as the module name of the module, that provides the entity type. However, this isn't always the case, e.g. the token type of the entity provided by
media_entity
module ismedia
, notmedia_entity
. Unfortunately, there doesn't seem to be an entity agnostic way to get the token type for an entity. At least I didn't find it. The best I came up with is this:This works for me for all entities, that I tested.
Comment #26
Lukas von BlarerThe patch in #22 works great for me.
Is the change suggested in #25 valid? @FeyP could you create a patch for this?
Comment #27
Peacog CreditAttribution: Peacog as a volunteer commentedI've added @FeyP's fix into the patch and tested it on nodes and taxonomy. It works for me but I haven't tested it with media_entity. If @FeyP could give it a whirl that would be great. Thanks!
Comment #28
Postovan Dumitru CreditAttribution: Postovan Dumitru at FFW commentedHello,
Using the patch from #27, and also using Content Moderation module(core, experimental), throws an error when trying to enable moderation states for content types:
I hope this is helpful, Cheers.
Comment #29
Postovan Dumitru CreditAttribution: Postovan Dumitru at FFW commentedSorry guys, having a rough start of the week, appended the module name to the patch. And changed the numbers accordingly.
Comment #30
Postovan Dumitru CreditAttribution: Postovan Dumitru at FFW commentedPlease disregard the previous files attached, it seems I misunderstood some tutorials.
Attaching correct patch.
Comment #31
Smith76 CreditAttribution: Smith76 commentedThanks ... it works well :-)
Comment #32
hansfn CreditAttribution: hansfn as a volunteer commentedThis still works - great! (Git complained because there was no EOL in last line in auto_entity_label-2755445-30.patch - easy to fix.)
I suggest that the current patch (in comment 30) is committed to get the module in a working state. Any outstanding problems can be moved to separate issues.
Comment #33
NickDickinsonWilde+1 works fine.
Comment #34
purushotam.rai CreditAttribution: purushotam.rai at QED42 commentedPatch needs reroll
Comment #35
Peacog CreditAttribution: Peacog as a volunteer commentedHere's a reroll, changing slightly the additional check added in #30 and adding back some code that was left out in #30. It'd be great to get this committed so please review and report back here whether or not it works for you.
Comment #36
gngn CreditAttribution: gngn at Computer Manufaktur GmbH commentedI just tested #35 (starting with git from https://www.drupal.org/project/auto_entitylabel/git-instructions).
I tried Evaluate PHP in pattern and got
So I took a look and found in
AutoEntityLabelManager::generateLabel()
:The function is called
evalLabel()
notevalTitle()
.Patch and interdiff to #35 attached.
I also think that
evalLabel()
should check if the eval'ed code goes wrong and raise an error - but that's left for another day ;)Comment #37
gngn CreditAttribution: gngn at Computer Manufaktur GmbH commentedAlso the title field is not hidden (Automatically generate the label and hide the label field).
Before hiding the title field
auto_entitylabel_form_alter()
checks$entitiy is an
AutoEntityLabelManager
which implementsAutoEntityLabelManagerInterface
.Neither AutoEntityLabelManager nor AutoEntityLabelManagerInterface implement ContentEntityInterface, so the test
instanceof ContentEntityInterface
allways fails and the title field is not hidden.So checking
instanceof \Drupal\auto_entitylabel\AutoEntityLabelManagerInterface
should do the trick (and does for me).Comment #38
Peacog CreditAttribution: Peacog as a volunteer commentedThanks @gngn. Your patch works for me too.
Comment #39
AndreaMaggi CreditAttribution: AndreaMaggi commentedComment #40
AndreaMaggi CreditAttribution: AndreaMaggi commentedComment #41
AndreaMaggi CreditAttribution: AndreaMaggi commentedHi, it's the first time I comment!
So, the last patch works. It should be nice if this patch include this simple bug a fix.
I also want to allert about another bug:
When you have the option enabled: "Automatically generate the label and hide the label field" and you use translations, whenever you delete a translation an exception is arisen:
InvalidArgumentException: The entity object refers to a removed translation (it) and cannot be manipulated. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 464 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
reported at the page urlit/node/142/delete
but anycase the translaction get eresed.Hope this helps.
Regards.
Comment #42
gngn CreditAttribution: gngn at Computer Manufaktur GmbH commented@AndreaMaggi
(You link to /node/node/2850962 instead of /node/2850962 - I think you missed the leading slash)
Comment #43
AndreaMaggi CreditAttribution: AndreaMaggi commented@gngn
Thenks for the replay. Yes the patch was the one you have included. Sorry but I had uderstand that here were collected all the fixes for the actual release that won't work without this patch. I manually update my file (there are only two line to change).
For the other iusse with the translation I understand that I have to apen a new issue, but I do not have the experience to do that. I do not relly understand how to use this bug fixes iusse reports. My bad, but I have started wokink by my own with Drupal just two mouths ago.
Thans anyway.
Comment #44
gngn CreditAttribution: gngn at Computer Manufaktur GmbH commented@AndreaMaggi: You're doing fine :)
You can create a new issue from the project's issue page.
There is a link "Create a new issue" at the top.
Following it you will also get links to stuff like How to create a good issue.
And for me the module is working with patch #37.
Comment #45
purushotam.rai CreditAttribution: purushotam.rai at QED42 commentedPatch needs reroll.
Comment #46
Peacog CreditAttribution: Peacog as a volunteer commentedOK, the recent commits messed things up a bit because a patch that depended on this one was committed #2822546: Auto Label tab not displayed for taxonomy. I've done a reroll which I think gets us back on track.
Interdiff threw an error, so I've done a simple diff between this new patch and the one from #37. Please review and let's try to get this committed soon.
Comment #48
purushotam.rai CreditAttribution: purushotam.rai at QED42 commentedComment #49
purushotam.rai CreditAttribution: purushotam.rai at QED42 commentedThanks a lot for all your valuable inputs. Now definitely we can create RC release.
Comment #51
geek-merlinGreat we have this in! Rock on!
Comment #52
Peacog CreditAttribution: Peacog as a volunteer commentedGreat news! Thanks for committing!