Problem/Motivation

When I select "Automatically generate the label and hide the label field"
and configure token : 'R-[node:nid]_[current-date:html_year' it works fine,

however when I select

"Automatically generate the label if the label field is left empty" with the same token R-[node:nid]_[current-date:html_year'
node:nid won't work and create R-_2021 instead

Is it possible to fix it? I need to migrate nids from the old site and cannot be changed, hence title will stay :R-[old_nid] which is fine, but when I create new content type it won't use node:nid. just already mentioned R-_2021

Steps to reproduce

-already mentioned

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

coaston created an issue. See original summary.

splash112’s picture

Did you find a solution to this? My entity tokens suddenly stopped working on 1 entity...

splash112’s picture

Noticed I had switched on Token CUSTOM DISPLAY SETTINGS. Switching that off again filled the entity label nicely.
Weird, as the config was exported from staging where it worked perfectly.

coaston’s picture

Hm, not sure i understand, does it mean you find a workaround?

splash112’s picture

Could be a bug, but would need to look into that. Noticed that node tokens for this module worked in 1 content type but not in the other.
Switching off custom display type for tokens at /admin/structure/types/manage/***/display fixed it.

ivnish’s picture

Status: Active » Closed (duplicate)
coaston’s picture

Ivnish - how this can be a duplicate if this is related to d8/9 version and you posted d7 link?
Please reopen it - still waiting for the patch!

coaston’s picture

Status: Closed (duplicate) » Needs work
kksandr’s picture

Hello, I faced the same problem.
The problem is that the module, if possible, populates the label in the presave hook where the entity ID is not yet available. And after that, the label is no longer considered empty and is not updated.

My solution is to add the ability to force the label to be re-save. To do this, a temporary label value is written to the label for new entities that do not have an identifier, which will also be considered empty for the next save. The new option in the form is called "Generate by resaving".

kksandr’s picture

Status: Needs work » Needs review
marcoliver’s picture

Status: Needs review » Reviewed & tested by the community

I just tested the patch from #9 and it works fine. Seems like a good solution!

Marking as RTBC.

dqd’s picture

Title: [node:nid] - label field is left empty » [node:nid] not added in label in a certain combination of settings
Version: 8.x-3.0-beta4 » 8.x-3.x-dev
Status: Reviewed & tested by the community » Postponed (maintainer needs more info)
/**
 * The temporary label for prevent database errors.
 */

Apart from some minor trouble in the patch which needs to be corrected/clarified, this issue is far behind and we need more reports if this issue is still reproducable at latest dev and latest stable release, which is 2 years younger than this issue here.

Additionally the patch needs to be rerolled then for latest dev if the issue still persist. Than we can think about a backport if required for circumstances where older versions of this project are mandatory.

kksandr’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1021 bytes

Apart from some minor trouble in the patch

The solution you quote is already used in this module. The patch just moves this string constant into a class constant for easy reuse.

This issue is still relevant, I have opened a merge request for the current version of the module.
I also added a test that reproduces the problem.

It would be nice if the module switched to Gitlab CI or fixed Drupal CI for automated testing.
Because the default tests fail via a deprecation error:

---Errors---
You are using the deprecated option "--no-suggest". It has no effect and will break in Composer 3.

dqd’s picture

@kksandr: Thanks for coming back on this. Much appreciated.

It would be nice if the module switched to Gitlab CI or fixed Drupal CI for automated testing.

Agreed. Feel free to open an issue for that. I would embrace that! +1 for the reminder.

The solution you quote is already used in this module.

Minor misunderstanding here: I was referring to minor gramma and typo in code comments as a minor nit pick review.

Thanks for the reroll! +1 For all the hard work in here. Will review the reroll asap.