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.

CommentFileSizeAuthor
#46 auto_entity_label-2755445-46.patch40.91 KBPeacog
#46 diff-2755445-37-46.txt10.37 KBPeacog
#37 interdiff-2755445-36-37.txt851 bytesgngn
#37 auto_entity_label-2755445-37.patch42.15 KBgngn
#36 interdiff-2755445-35-36.txt709 bytesgngn
#36 auto_entity_label-2755445-36.patch42.12 KBgngn
#35 auto_entity_label-2755445-35.patch42.14 KBPeacog
#35 interdiff-2755445-27-35.txt1.89 KBPeacog
#35 interdiff-2755445-30-35.txt3.69 KBPeacog
#30 interdiff-2755445-27-30.txt.txt2.25 KBPostovan Dumitru
#30 auto_entity_label-2755445-30.patch42.15 KBPostovan Dumitru
#29 auto_entity_label-2755445-29.patch38.3 KBPostovan Dumitru
#29 interdiff-2755445-27-29.txt2.31 KBPostovan Dumitru
#28 interdiff-2755445-27-28.txt2.31 KBPostovan Dumitru
#28 2755445-28.patch38.3 KBPostovan Dumitru
#27 auto_entity_label-2755445-27.patch42.05 KBPeacog
#27 interdiff-2755445-22-27.txt1.45 KBPeacog
#22 auto_entity_label-2755445-22.patch41.79 KBPeacog
#22 interdiff-2755445-20-22.txt1.02 KBPeacog
#20 auto_entity_label-2755445-20.patch40.92 KBPeacog
#20 interdiff-2755445-17-20.txt3.21 KBPeacog
#17 auto_entity_label-2755445-17.patch40.39 KBPeacog
#17 interdiff-2755445-16-17.txt742 bytesPeacog
#16 auto_entity_label-2755445-16.patch40.37 KBSurfinSpirit
#15 interdiff-2755445-12-15.txt747 bytesSurfinSpirit
#15 auto_entity_label-2755445-15.patch29.46 KBSurfinSpirit
#12 entity_forms_should-2755445-12.patch40.34 KBPeacog
#12 interdiff-2755445-10-12.txt1.56 KBPeacog
#11 entity_forms_should-2755445-11.patch40.34 KBPeacog
#11 interdiff-2755445-10-11.txt1.55 KBPeacog
#10 entity_forms_should-2755445-10.patch39.22 KBPeacog
#2 entity_forms_should-2755445-2.patch2.9 KBpiyuesh23
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

piyuesh23 created an issue. See original summary.

piyuesh23’s picture

Attaching patch here.

piyuesh23’s picture

Status: Active » Needs review
piyuesh23’s picture

Issue tags: +#drupalIndiaSprint

purushotam.rai’s picture

Status: Needs review » Fixed
webcultist’s picture

Throws an error when used with the latest version of https://www.drupal.org/project/yamlform.

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\yamlform\Entity\YamlFormSubmission::getType() in auto_entitylabel_form_alter() (line 29 of modules/contrib/auto_entitylabel/auto_entitylabel.module).
auto_entitylabel_form_alter(Array, Object, 'yamlform_submission_newsletter_subscription_form') (Line: 501)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'yamlform_submission_newsletter_subscription_form') (Line: 816)
Drupal\Core\Form\FormBuilder->prepareForm('yamlform_submission_newsletter_subscription_form', Array, Object) (Line: 29)
Drupal\webprofiler\Form\FormBuilderWrapper->prepareForm('yamlform_submission_newsletter_subscription_form', Array, Object) (Line: 272)
Drupal\Core\Form\FormBuilder->buildForm('yamlform_submission_newsletter_subscription_form', Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'default') (Line: 601)
Drupal\yamlform\Entity\YamlForm->getSubmissionForm(Array) (Line: 75)
Drupal\yamlform\Plugin\Block\YamlFormBlock->build() (Line: 203)
Drupal\block\BlockViewBuilder::preRender(Array)
call_user_func('Drupal\block\BlockViewBuilder::preRender', Array) (Line: 376)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 151)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 152)
Drupal\Core\Render\Renderer->renderPlain(Array) (Line: 166)
Drupal\Core\Render\Renderer->renderPlaceholder('', Array) (Line: 659)
Drupal\Core\Render\Renderer->replacePlaceholders(Array) (Line: 544)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 139)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 140)
Drupal\Core\Render\Renderer->renderRoot(Array) (Line: 258)
Drupal\Core\Render\HtmlResponseAttachmentsProcessor->renderPlaceholders(Object) (Line: 131)
Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments(Object) (Line: 45)
Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond(Object, 'kernel.response', Object)
call_user_func(Array, Object, 'kernel.response', Object) (Line: 61)
Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(Object, 'kernel.response', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object) (Line: 140)
Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('kernel.response', Object) (Line: 184)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 166)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 38)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 652)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
webcultist’s picture

Status: Fixed » Needs work
webcultist’s picture

Seems to be related to this Issue

Peacog’s picture

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

Peacog’s picture

I'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.

Peacog’s picture

Title: Entity forms should honor Auto Entity label configuration » Auto Entity label settings should be appied when an entity is saved
Issue summary: View changes
FileSize
1.56 KB
40.34 KB

Sorry, there was a permissions bug in the last patch. Use this one instead.

VladimirAus’s picture

Status: Needs work » Reviewed & tested by the community

Looks good. Works well with Taxonomies and Yaml Forms.

Peacog’s picture

Title: Auto Entity label settings should be appied when an entity is saved » Auto Entity label settings should be applied when an entity is saved

Just fixing a typo in the issue title...

Thanks for reviewing @VladimirAus

SurfinSpirit’s picture

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

SurfinSpirit’s picture

Attaching new patch because of some diff export issues.

Peacog’s picture

Issue tags: -#drupalIndiaSprint
FileSize
742 bytes
40.39 KB

Thanks @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.

SurfinSpirit’s picture

Just noticed that 'admin/config/content/entity_browser' gives the same error, looks like the if statement in 'auto_entitylabel_entity_type_alter' needs improvements.

Peacog’s picture

Assigned: Unassigned » Peacog
Status: Reviewed & tested by the community » Needs work

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

Peacog’s picture

OK, 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

Peacog’s picture

Assigned: Peacog » Unassigned
Peacog’s picture

Issue summary: View changes
FileSize
1.02 KB
41.79 KB

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

Smith76’s picture

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

Peacog’s picture

Title: Auto Entity label settings should be applied when an entity is saved » Auto Entity label does not set entity labels and breaks contrib modules
Category: Task » Bug report
Issue summary: View changes
FeyP’s picture

Thanks for the patch, it seems to work well for us so far. I just noticed one issue regarding the token browser:

     // Display the list of available placeholders if token module is installed.
     if (\Drupal::moduleHandler()->moduleExists('token')) {
       $form['auto_entitylabel']['token_help'] = array(
         '#theme' => 'token_tree_link',
-        '#token_types' => array($entity_type),
+        '#token_types' => array($this->entity_type_provider),
         '#dialog' => TRUE,
       );
     }

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 is media, not media_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:

    // Display the list of available placeholders if token module is installed.
    $moduleHandler = \Drupal::moduleHandler();
    if ($moduleHandler->moduleExists('token')) {
      $tokenInfo = $moduleHandler->invoke($this->entity_type_provider, 'token_info');
      $tokenTypes = isset($tokenInfo['types']) ? array_keys($tokenInfo['types']) : [];

      $form['auto_entitylabel']['token_help'] = array(
        '#theme' => 'token_tree_link',
        '#token_types' => $tokenTypes,
        '#dialog' => TRUE,
      );
    }

This works for me for all entities, that I tested.

Lukas von Blarer’s picture

The patch in #22 works great for me.

Is the change suggested in #25 valid? @FeyP could you create a patch for this?

Peacog’s picture

I'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!

Postovan Dumitru’s picture

Hello,

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:

The website encountered an unexpected error. Please try again later.
Recoverable fatal error: Argument 1 passed to Drupal\auto_entitylabel\EntityDecorator::decorate() must be an instance of Drupal\Core\Entity\ContentEntityInterface, instance of Drupal\node\Entity\NodeType given, called in /var/www/docroot/modules/contrib/auto_entitylabel/auto_entitylabel.module on line 51 and defined in Drupal\auto_entitylabel\EntityDecorator->decorate() (line 74 of modules/contrib/auto_entitylabel/src/EntityDecorator.php). 

I hope this is helpful, Cheers.

Postovan Dumitru’s picture

Sorry guys, having a rough start of the week, appended the module name to the patch. And changed the numbers accordingly.

Postovan Dumitru’s picture

Please disregard the previous files attached, it seems I misunderstood some tutorials.

Attaching correct patch.

Smith76’s picture

Thanks ... it works well :-)

hansfn’s picture

Status: Needs review » Reviewed & tested by the community

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

NickDickinsonWilde’s picture

+1 works fine.

purushotam.rai’s picture

Status: Reviewed & tested by the community » Needs work

Patch needs reroll

Peacog’s picture

Status: Needs work » Needs review
FileSize
3.69 KB
1.89 KB
42.14 KB

Here'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.

gngn’s picture

I just tested #35 (starting with git from https://www.drupal.org/project/auto_entitylabel/git-instructions).
I tried Evaluate PHP in pattern and got

PHP Fatal error:  Call to undefined method Drupal\\auto_entitylabel\\AutoEntityLabelManager::evalTitle()
in [...]/auto_entitylabel/src/AutoEntityLabelManager.php on line 243

So I took a look and found in AutoEntityLabelManager::generateLabel():

// Evaluate PHP.
    if ($this->getConfig('php')) {
      $output = $this->evalTitle($output, $this->entity);
    }

The function is called evalLabel() not evalTitle().

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 ;)

gngn’s picture

Also 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

    [...]
    $decorator = \Drupal::service('auto_entitylabel.entity_decorator');
    /** @var \Drupal\auto_entitylabel\AutoEntityLabelManager $entity */
    $entity = $decorator->decorate($form_state->getFormObject()->getEntity());

    if ($entity instanceof ContentEntityInterface) {
      [...]

$entitiy is an AutoEntityLabelManager which implements AutoEntityLabelManagerInterface.
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).

Peacog’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @gngn. Your patch works for me too.

AndreaMaggi’s picture

AndreaMaggi’s picture

AndreaMaggi’s picture

Hi, 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 url it/node/142/delete but anycase the translaction get eresed.
Hope this helps.
Regards.

gngn’s picture

@AndreaMaggi

  • With "simple bug fix" you mean Some characters replaced with HTML entities, don't you?
    (You link to /node/node/2850962 instead of /node/2850962 - I think you missed the leading slash)
  • That patch was just adjusted from 'Active' to 'Patch (to be ported)' without any discussion...
  • Also I think it is a different issue, so I do not think it should be included here.
  • IMHO the same applies to your other issue with translations - I think it would be better to open a new issue for that one.
AndreaMaggi’s picture

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

gngn’s picture

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

purushotam.rai’s picture

Status: Reviewed & tested by the community » Needs work

Patch needs reroll.

Peacog’s picture

Status: Needs work » Needs review
FileSize
10.37 KB
40.91 KB

OK, 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.

purushotam.rai’s picture

Status: Needs review » Fixed
purushotam.rai’s picture

Thanks a lot for all your valuable inputs. Now definitely we can create RC release.

geek-merlin’s picture

Great we have this in! Rock on!

Peacog’s picture

Great news! Thanks for committing!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.