I've no idea if this is ECK doing it wrong, or auto_entitylabel making an assumption it shouldn't. But, when an eck entity is first saved it gets an auto_entityautolabel, however on subsequent saves this gets reverted to '%AutoEntityLabel%'.

What is happening is:-

auto_entitylabel in its hook_field_attach_submit() is setting the title (both on insert and update).

The hook was triggered from eck__entity__form_submit() which goes on to If we find a value set for a property lets just set it. set the title to what it was in the form which is '%AutoEntityLabel%'. It is set to this both on insert and update - I'm not sure why it's got that value on update when it could be the previously set title?

On insert it works because auto_entitylabel in its hook_entity_insert makes the label anew, because auto_entitylabel_is_needed() is called with the $reset switch true.

On update the calls to auto_entitylabel_is_needed() don't have $reset, so because a label has been set it does not do it again.

Comments

ekes’s picture

StatusFileSize
new526 bytes

Just to make the point, my work-around, if anyone needs it till someone can work out how to fix this properly, just forces update on presave.

pdcrane’s picture

I was having this same issue with Inline Entity Forms, but I patched it differently. See attached.

Also, this is my very first patch file following the directions here: https://www.drupal.org/node/707484

Hopefully I didn't screw it up =P

Anonymous’s picture

Status: Active » Needs review

Applying the patch in #2 solved the issue for me described at https://www.drupal.org/node/1980652#comment-9290785, whereas the patch in #1 didn't.

Marking this as 'needs review'.

cravecode’s picture

Patch #2 worked for me as well.

(My scenario was related to the Inline Entity Form problem)

cravecode’s picture

It may be a better solution to check for reset or "%AutoEntityLabel%" instead of always setting reset to true. That's just a suggestion though, I'm fine with how patch #2 currently works.

bforchhammer’s picture

It may be a better solution to check for reset or "%AutoEntityLabel%" instead of always setting reset to true. That's just a suggestion though, I'm fine with how patch #2 currently works.

That sounds like a good idea. I would rather not add special cases for specific modules... ;-)

cravecode’s picture

I'm submitting my patch that checks for both empty and "%AutoEntityLabel%". Because I needed to use some values from the $settings array, I had to change the order of the logic. With that in mind, i chose to make the steps pretty verbose for easier reading over fewer lines of code.

@broxen, thank you so much for creating the issue related to inline entity forms. Had I not found that issue, it could have taken me a while to figure out what was going on or I'd have ditch the idea of using this module all together.

@bforchhammer, this module is fantastic! Thanks for your work!

bforchhammer’s picture

Status: Needs review » Needs work

Thanks for your patch, looks good overall!

A few minor things:

  1. +++ b/auto_entitylabel.module
    @@ -195,13 +195,40 @@ function auto_entitylabel_field_attach_presave($entity_type, $entity) {
    + * @param bool $reset Forces the label to be set, even if a title has already been set.
    

    Line too long (>80). Maybe just move @param descriptions into new line... :)

  2. +++ b/auto_entitylabel.module
    @@ -195,13 +195,40 @@ function auto_entitylabel_field_attach_presave($entity_type, $entity) {
    +      || $entity->{$settings['title']} == '%AutoEntityLabel%');
    

    Let's put the %AutoEntityLabel% string into a constant at the top of the file.

  3. +++ b/auto_entitylabel.module
    @@ -195,13 +195,40 @@ function auto_entitylabel_field_attach_presave($entity_type, $entity) {
    +    // Check if the label is empty or forced and makes sure an existing label isn't overwritten if the autolabel is optional.
    

    Line too long :)

bforchhammer’s picture

+++ b/auto_entitylabel.module
@@ -195,13 +195,40 @@ function auto_entitylabel_field_attach_presave($entity_type, $entity) {
+ * @param string $entity_type The entity bundle.

This is actually the entity "type"; the "bundle" usually refers to things like node types (e.g. page, article)

@broxen, @ekes: can you guys give the patch a go and confirm that this solves the problem for you as well?

cravecode’s picture

@bforchhammer Thanks for the feedback! I'll post a updated patch soon. Are you sure $entity_type was just the actual type? I'm almost sure I remember it being the bundle. I'll verify when I update the patch.

I was going to suggest moving "%AutoEntityLabel%" into a constant but I figured it was out of scope for this issue. Sounds like you want it, so I'll include the new constant with my next patch.

cravecode’s picture

Status: Needs work » Needs review
StatusFileSize
new3.72 KB

I was wrong, $entity_type is just the type, not the bundle :)

Attached is the updated patch.

bforchhammer’s picture

Status: Needs review » Fixed

Works for me. Thanks!

  • cravecode authored 7a7d995 on 7.x-1.x
    Issue #2329729 by cravecode, broxen, ekes: Fixed ECK: Autolabel set on...
kamenrs’s picture

I've downloaded the last dev version form Drupal.org with this patch committed and the problem is still present.
After re-saving a commerce product the entity label is set to %AutoEntityLabel% (attribute).

CORRECTION: Sorry about that - actually it works as it should. It should be my mistake. Thanks a lot for your work.

cravecode’s picture

@kamenrs, I can't reproduce that. Here is what I've done so far:

  1. New clean installation of Commerce Kickstart
  2. Unchecked "Auto generate the product title" on: admin/structure/types/manage/product-display/fields/field_product
  3. Downloaded and enabled the 7.x-1.x-dev (2014-Nov-16) version of Automatic Entity Label.
  4. Cleared caches
  5. Set the title pattern on: admin/commerce/config/product-variation-types/product/auto_label and selected "Automatically generate the label and hide the label field"
  6. Clicked edit on a product variation via the inline entity form.
  7. Clicked "Update product"
  8. The title looked good, so I clicked edit again on the same product variation via the inline entity form
  9. Once more, clicked "Update product". The product variation title still looks correct.
  10. I clicked save for the product display, went back to the product variations, and the title was still correct.

Have you tried clearing your caches? Is there a different process you are taking than I've documented?

Thanks for the feedback!

kamenrs’s picture

@cravecode
Thank you very much for your lightning fast reply.
I apologize for this comment. It should have been my failure.
After some more tries I get the expected result. Everything works as it should. Really sorry about wasting your time.

Thanks for the time and efforts. I don't deserve them.

Thanks a ton for your great work. Please, excuse me.

cravecode’s picture

@kamenrs no problem! I'm working on a e-commerce site an just downloaded Commerce Kickstart when I saw your comment come in. I figured it would only take a minute to document my steps so why not help someone in the process.

Glad to hear it's working, the more testing, the better! Good luck!

Status: Fixed » Closed (fixed)

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