[PP-1] Enum cases stored in config

Created on 16 November 2023, 8 months ago
Updated 2 April 2024, 3 months ago

Problem/Motivation

Say we have this backed enum:

enum Fruits: string {
  case APPLE = 'apple';
  case PINEAPPLE = 'pineapple';
  case PLUM = 'plum';
}

And this schema definition:

mymodule.settings:
  type: config_object
  mapping:
    fruit:
      type: enum
      enum: '\Drupal\mymodule\Fruits'

I want to be able to store an enum case:

\Drupal::configFactory()->getEditable('mymodule.settings')
  ->set('fruit', Fruits::APPLE)
  ->save();

But in the backend only the scalar (apple) should be stored, mainly because of the serialization aspect. Note that this is the reason why backed enums were created, to resolve the backend roundtrip.

I want to be able to retrieve the enum case (not the scalar):

$fruit = \Drupal::config('mymodule.settings)->get('fruit');

$fruit should be Fruits::APPLE, not apple

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Postponed

Version

11.0 πŸ”₯

Component
ConfigurationΒ  β†’

Last updated 9 minutes ago

Created by

πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024