New changes to set label logic cause integrity constraint violation

Created on 27 August 2024, 3 months ago
Updated 2 September 2024, 3 months ago

Problem/Motivation

Two previous issues: https://www.drupal.org/project/auto_entitylabel/issues/3239799 πŸ› %AutoEntityLabel% title when "Preserve already created node titles." option is enabled Needs work and https://www.drupal.org/project/auto_entitylabel/issues/3076302 πŸ› Set Label runs two times on node creation Needs review 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.

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡·πŸ‡ΈSerbia miksha

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024