Doesn't work if title label is overridden

Created on 5 January 2023, over 1 year ago
Updated 30 June 2023, 12 months ago

Problem/Motivation

If you change the label of the title field for a content type, then unique validation on the title field does not work.

Steps to reproduce

1. Create a new content type.
2. In the "Title field label" field, change Title to something else.
3. Enable unique validation.
4. Save content type.
3. Create a new record of the content type with title = "test". Save.
4. Create a 2nd new record of the content type with title = "test". Save. Unique validation should show an error and prevent the save, but does not.

Proposed resolution

I dug into this and found this information which led me to a solution: https://www.drupal.org/project/drupal/issues/3193351 πŸ› Adding a constraint to a BaseField is broken if the basefield is overwritten Needs work

What happens is that after the title label is changed from the default "Title" to something else, the title field is considered a bundle field and the constraint must be added in hook_entity_bundle_field_info_alter().

Patch attached.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada jdhildeb

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024