Problem/Motivation
Some entities, like core's User entity, don't have bundles; or rather, they have exactly one bundle with the same name as the entity, but no type configuration entity (like NodeType for Node entities). See the Entity topic on api.drupal.org for more information.
Currently, however, auto_entitylabel is only capable of generating automatic entity labels for entities that have type configuration entities. In particular, \Drupal\auto_entitylabel\Form\AutoEntityLabelForm exits with a fatal error (aka WSOD) if an entity type configuration entity cannot be found. My gut (which could be wrong!) says AutoEntityLabelForm is probably the biggest hurdle in this.
However, given that this module simply constructs a label string from tokens, I don't think it's necessary to require type configuration entities.
Related issues
From what I can tell, the following issues are related to, and may be partially or fully fixed by completing this plan/issue:
- #2909742: Support of User Profiles
- #2926779: Automatic Entity Label doesn't work with taxonomy terms
- #2856152: Auto Label tab condition broken
- #2859953: Automatic label for Views
Proposed resolution
Modify this module so that it will function without requiring type configuration entities.
Remaining tasks
- #2923876: Broken when provider !=entityTypeId
#2945361: Clean up AutoEntityLabelForm(postponed in favor of 2923876)
User interface changes
Unknown; but hopefully none.
API changes
Unknown, but hopefully the public API for this module will not change.
Data model changes
Unknown, but hopefully none.
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | 2945387-28.patch | 7.69 KB | joegraduate |
| #19 | 2945387-19-support-bundleless-entities.patch | 7.68 KB | pasqualle |
| #14 | 2945387-14-support-bundleless-entities.patch | 11.78 KB | pasqualle |
Issue fork auto_entitylabel-2945387
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mparker17I've postponed #2945361: Clean up AutoEntityLabelForm in favor of the changes in #2923876: Broken when provider !=entityTypeId
Comment #3
panchoI think I got it working... :)
Comment #4
panchoSorry, wrong patch in #3.
Comment #5
panchoNow this definitely is the right patch. Manually tested to work as advertised.
I got Automatic Entity Labels working for:
* custom bundle-less content entities implementing the link template 'auto-label'
* Core's bundle-less, fieldable content entities (= Feed, User).
The enclosed, comprehensive patch against latest dev builds upon and therefore includes the other patch in #2945361-5: Clean up AutoEntityLabelForm. Would be great to start with having #2923876-28: Broken when provider !=entityTypeId committed, so we can get forward with this.
Comment #6
w01f commentedThis patch lets auto entity label work great with users - is it possible to extend this to work with commerce store setup at: https://www.supersite.com/admin/commerce/config/store-types/online/edit/...
Update: Also would be great if it worked with commerce products: https://www.supersite.com/admin/commerce/config/product-types/awesome-pr...
Comment #7
colanComment #8
dwwAlas, #5 no longer applies cleanly to either 8.x-2.x nor 8.x-3.x branches. Reroll would be wonderful. @Pancho is that easy for you?
Thanks!
-Derek
Comment #9
dwwMeanwhile, some minor nits I found reviewing #5 closely:
Code style to have newlines after break;
CS:
Out of scope.
I think this would be more readable as:
Excited to test a working patch... seems like a big win for auto_entitylabel!
Thanks,
-Derek
Comment #10
bdimaggioRe-rolled against current 8.x-3.x. This is working for a bundle-less custom entity we're using, although I should note that I haven't tested with bundle-less core entities like User.
Also note that in order to take advantage of this new state of the code, I had to add a hook in my own custom module:
Comment #11
dkosbob commentedThanks for this, y'all. This is working well when updating an existing user, but it's preventing a new user from being created due to the percent signs in the widget default value ('%AutoEntityLabel%').
I just made a very small change to use '.AutoEntityLabel.' as the default value instead. It looks arbitrary to me, but I may be missing something
Comment #12
colanLet's start providing interdiffs with patches so they're easier to review. See https://www.drupal.org/documentation/git/interdiff .
Comment #13
dkosbob commentedThat's empty, pulled the trigger too early, sorry.
Comment #14
pasquallereroll
Comment #15
tijsdeboeckTested patch #14 with 3.0.0-beta4, works for me!
Comment #16
daniel-san commentedHoping to help, but I have been trying to apply patch #14 to dev version with no success. I keep getting errors.
I downloaded the patch into the dev version of the module and then used
git apply -vwith the patch name.errors:
Checking patch auto_entitylabel.module...
error: while searching for:
*/
use Drupal\auto_entitylabel\AutoEntityLabelManager;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\ContentEntityInterface;
error: patch failed: auto_entitylabel.module:6
error: auto_entitylabel.module: patch does not apply
Checking patch src/AutoEntityLabelManager.php...
Checking patch src/Form/AutoEntityLabelForm.php...
error: while searching for:
use Drupal\auto_entitylabel\AutoEntityLabelManager;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
error: patch failed: src/Form/AutoEntityLabelForm.php:4
error: src/Form/AutoEntityLabelForm.php: patch does not apply
Checking patch src/Plugin/Derivative/AutoEntityLabelConfigTask.php...
Maybe I'm doing it wrong? I've tried to follow the applying patches guidelines and all, but I'm not having any success. If anyone wants to provide a bit of guidance, I'd be glad to put some time into testing.
Thanks.
Dan
Comment #17
pasqualleYes, it seems the patch needs a new reroll. It does not apply to the latest dev release any more.
Comment #18
daniel-san commentedOk, thank you so much for the response. Is there something I can do, or do we just wait to test after the re-roll?
Comment #19
pasquallereroll, with unnecessary changes removed.
Comment #20
daniel-san commentedDrupal 9.3.13
auto_entitylabel 8.x-3.x-dev
Patch #19 applied
Created First Name field on set Auto Label to 'Automatically generate the label and hide the label field' with token [user:field_first_name]
Created new user with a first name in field and it set the user title as expected. Changed the first name field to another name and it updated correctly.
Tried creating a custom module per comment #10 for a custom entity in my dev site and could not get a auto label page for that entity.
Is this code supposed to allow for custom entities to have auto label at this point, or is this just for the User entity?
Comment #21
pasqualleFor custom entities
the patch from issue #2829571: Provide a hook for contrib modules that want to implement automatic labels is needed, and alsoneed to implement thenewhook explained in the issue.Comment #22
daniel-san commentedFrom your strikethrough on comment #21, I take it that you mean to apply the patch in #19 and then use the following hook customized for the custom entity.
I have auto_entitylabel 8.x-3.x-dev installed.
I have applied the patch from #19.
I have created a custom module to implement the hook for the override. I my case, the custom module is referencing my entity module called 'student_entity' and the entity is 'student'
After installing, patching, and then writing and installing the custom module for the hook, I get a 'Page not found' when going to the path and adding /auto-label to the end.
my implementation of the hook:
In the path, I used '/admin/structure/student' because that's how you get to the entity settings page. Adding settings on the end, as in comment #10, gets a page not found as well. So, I am adjusting the path in my hook.
Hoping I'm on the right track and can provide some positive feedback.
Comment #23
peter caritas commentedThis is what worked for me:
Apply the patch in #19
In the .module file for my custom entity module I added the following:
Replacing mymodule with the name of your module and my_entity with the name of the entity (and any other changes to the path to match where your entity admin lives.
Comment #24
adaddinsaneI just added this and this worked for me:
Including "/settings" did not work.
Though if you are a developer and using custom entities then you should have access to the entity configuration so you just need to add this:
which is a lot cleaner.
Comment #25
adriancidFor custom entities #19 and #23 made the job.
Comment #26
jonmcl commentedPotentially major problem with the else statement in this block of code:Not all entity form displays are going to have a label field in the form. Assigning a non-existent form element to $widget by reference actually created the element with a value of null;Problem is thatContentEntityForm::copyFormValuesToEntitythen gets called and because the label widget was added to the form (with a value of null), ::copyFormValuesToEntity then sets the label to be null.This is probably a problem only when auto_entitylabel is disabled for a particular entity type and when the label widget is not present in the form currently being submitted.UPDATE: I think this is a bug in the module itself and not directly related to this patch.FINAL UPDATE: Never mind. I am an idiot :)
It appears we had a form item element (markup) using 'label' as it's key and that is why ::copyFormValuesToEntity was attempting to set the entity's label.
Comment #27
jonmcl commentedSetting back to "Needs review"
Comment #28
joegraduateRe-rolled patch from #19 against latest 8.x-3.x branch. The existing patch no longer applied after the latest changes included in the 8.x-3.2 release.
Comment #30
orkutmuratyilmazthe patch #28 works great:)