Support entities without bundles (User, etc.)

Created on 16 February 2018, over 6 years ago
Updated 12 June 2024, 5 months ago

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:

Proposed resolution

Modify this module so that it will function without requiring type configuration entities.

Remaining tasks

  1. #2923876: Broken when provider !=entityTypeId
  2. (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.

Feature request
Status

Needs review

Version

3.0

Component

Code

Created by

🇨🇦Canada mparker17 UTC-4

Live updates comments and jobs are added and updated live.
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 Peter Caritas

    This is what worked for me:

    Apply the patch in #19

    In the .module file for my custom entity module I added the following:

    /**
     * Implements hook_entity_type_alter().
     */
    function mymodule_entity_type_alter(array &$entity_types) {
    
      /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
      $entity_types['my_entity']->setLinkTemplate('auto-label', '/admin/structure/my_entity/settings/auto-label');
    
    }
    

    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.

  • 🇬🇧United Kingdom adaddinsane

    I just added this and this worked for me:

    function mymodule_entity_type_alter(array &$entity_types): void {
      /** @var EntityTypeInterface[] $entity_types */
      $entity_types['my_entity']->setLinkTemplate('auto-label', '/admin/structure/my_entity/auto-label');
    }
    

    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:

     *   links = {
     *     "canonical" = "/admin/structure/my_entity/{my_entity}",
     *     "add-form" = "/admin/structure/my_entity/add",
     *     "edit-form" = "/admin/structure/my_entity/{my_entity}/edit",
     *     "delete-form" = "/admin/structure/my_entity/{my_entity}/delete",
     *     "collection" = "/admin/structure/my_entity",
     *     "auto-label" = "/admin/structure/my_entity/auto-label",
     *   },
    

    which is a lot cleaner.

  • 🇨🇦Canada adriancid Montreal, Canada

    For custom entities #19 and #23 made the job.

  • Status changed to Needs work 9 months ago
  • 🇺🇸United States JonMcL Brooklyn, NY

    Potentially major problem with the else statement in this block of code:

        // Special treatment for Core's user entity.
        if ($entity_type_id == 'user') {
          $widget = &$form['account']['name'];
        }
        else {
          $widget = &$form[$label]['widget'][0]['value'];
        }
    

    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 that ContentEntityForm::copyFormValuesToEntity then 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.

  • Status changed to Needs review 9 months ago
  • 🇺🇸United States JonMcL Brooklyn, NY

    Setting back to "Needs review"

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 7.3 & MySQL 8
    last update 5 months ago
    Composer error. Unable to continue.
  • 🇺🇸United States joegraduate Arizona, USA

    Re-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.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 7.3 & MySQL 8
    last update 5 months ago
    Composer error. Unable to continue.
  • Pipeline finished with Success
    5 months ago
    Total: 199s
    #197668
Production build 0.71.5 2024