Problem/Motivation
Two previous issues (#3239799: %AutoEntityLabel% title when "Preserve already created node titles." option is enabled and #3076302: Set Label runs two times on node creation) were tackling set label options and the later issue introduced changes to set label logic.
But I am sorry but I do not seem to understand the new logic. For example if I check Automatically generate the label and hide the label field and my title field is required. And then also I check Preserve already created node titles. I end up with Integrity constraint violation: 1048 Column 'title' cannot be null because code inside auto_entitylabel_entity_presave for $entity->isNew() skips the next check because it has a check for Preserve already created node titles. checkbox value.
The way I understand option Preserve already created node titles. is e.g. I set title to use date token. I want to set titles automatically with the same pattern and hide title field from user for consistency of title naming and I set Automatically generate the label and hide the label field. Then on initial node save I get title set automatically and I want to preserve it on the next node update. So with these two options combined I end up with SQL integrity error. And this option to preserve already created titles is only visible with option that sets title automatically and hides title field.
Therefore I don't understand if code comment:
// Handle the case where the automatic label is optional.
// Check to see if isTitlePreserved is set. If the autolabel is
// optional AND the user has filled this title in then the
// the autolabel should not be set.
fits with the code checks below.
Also what I think happens is that Preserve already created node titles. checkbox (which is visible only in combination with Automatically generate the label and hide the label field) doesn't seem to be set to unchecked when being hidden if we switch options. e.g. I check Automatically generate the label and hide the label field and I also check Preserve already created node titles. and save. Then I go back and choose e.g. Automatically generate the label if the label field is left empty which hides Preserve already created node titles. but it's value when debugging seems to be true.
Issue fork auto_entitylabel-3470585
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
dqdThanks for the report. Good finding! +1 Let's investigate further.
Comment #3
dqdWrong reference (edited)
Comment #4
anybodyThanks for the report! @grevil and me will also take a look at it asap!
The Form States API bugs should be fixable quite easy, if we can be sure they exist, as first step.
Comment #5
aaronbaumanSame issue for me.
Comment #6
eduardo morales albertiAre there any updates on it?
Comment #7
eduardo morales albertiMaybe the issue #3260103: Automatic entity label does not take into account the field constraints could help
Comment #8
vensiresComment #9
mradcliffeI have custom code that creates a node and prior to the change I was able to not set a title value using the create method on the entity storage handler. It looks like if I provide the value of "%AutoEntityLabel%", then programmatically created node is successful without the integrity constraint violation exception.
This comes from auto_entitylabel_entity_presave(), which checks if the label is equal to the placeholder value, but if the label is NULL, then it won't do anything.
I think the previous behavior could be maintained if the check included NULL and the placeholder value.
Comment #10
anybody@mradcliffe sound good, could you prepare a MR draft?
Comment #12
mradcliffeI don't think I was correct about this, but there are tests now.