Add a 'machine_name' widget for string field types with a UniqueField constraint

Created on 11 March 2016, almost 9 years ago
Updated 16 May 2023, over 1 year ago

Problem/Motivation

Please guide me what changes I need to do for make machine name working for content entity.

Currently in Drupal 8, a 'machine_name' widget is available only on primary identifiers of config entities, as content entities were expected to use serial entity identifiers only.

Some specific content entity types, however, are bordering to configuration and are therefore better identified by a string. Use cases include Core's new Workspace, Entityqueue's EntitySubqueue, FillPDF's FillPDF forms โ†’ and the OP's contrib PET entity types.

This constitutes a regression from D7 where 'machine_name' fields were available as entity identifiers.

Proposed resolution

  1. Create a machine_name widget
  2. Allow 'string' type primary identifiers to specify the 'machine_name' widget in a content entity type's BaseFieldDefinition.
  3. Switch Core's Workspace entity to using a 'machine_name' widget on its 'string'-type id field replacing the current, ugly workaround.

Remaining tasks

User interface changes

- none -

API changes

- none -

Data model changes

- none -

Original issue

I'm trying to port PET โ†’ module, it uses custom entity to manage mail templates.
It has a machine name field, which I'm not able to make in Drupal 8. I checked code of Drupal 8 core, it uses machine name field for config type entities only, I did same way but it does not behave like machine name.

Please guide me what changes I need to do for make machine name working for content entity. Also let me know if this is an issue in core, I think the way fields are rendered in content entity might be the reason.

Current code can be seen here http://cgit.drupalcode.org/pet/tree/.

๐Ÿ“Œ Task
Status

Needs review

Version

10.1 โœจ

Component
Fieldย  โ†’

Last updated 3 days ago

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia Sharique

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

Merge Requests

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.71.5 2024