Define bundle classes via attributes

Created on 4 August 2022, almost 2 years ago
Updated 2 January 2024, 6 months ago

Problem/Motivation

Currently to declare a bundle class you have to implement hook_entity_bundle_info_alter() and set the class for each bundle. If you have many classes scattered across many modules you need to implement this many times. This can also lead to many use statements in your .module files to import all the classes just to reference the class name.

It would be a nicer experience to simply place an attribute on the bundle class.

#[Bundle(
  entityType: 'node',
  bundle: 'article',
  label: new TranslatableMarkup('Article'),
)]
class Article extends Node { }

Steps to reproduce

N/A

Proposed resolution

The Bundle Class Attribute → module provides a proof of concept using plugins.

Such a simple feature could exist in core.

Remaining tasks

  • Determine if this is something we want in core
  • Determine if there is a better approach
  • Implement the core solution

User interface changes

N/A

API changes

Bundle classes can be declared via attributes.

Data model changes

N/A

Release notes snippet

TBD

✨ Feature request
Status

Needs work

Version

11.0 🔥

Component
Entity  →

Last updated 1 day ago

  • Maintained by
  • 🇬🇧United Kingdom @catch
  • 🇨🇭Switzerland @Berdir
  • 🇩🇪Germany @hchonov
Created by

🇦🇺Australia mstrelan

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

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