Using bundle classes to build content types with built-in behaviors
summary
Shows how Drupal entity bundle classes replace scattered hooks and subscribers by putting content-type rules into PHP classes wired with hook_entity_bundle_info_alter. Concrete examples: featureable interface with news returning false if older than 45 days, teaserable trait for summaries and canonical URLs, a readtime service that divides word count by 220 wpm, and an entity-knowledge interface with getKnowledgeEntities / setKnowledgeParent / setKnowledgeStatus for search-index syncing. Code and examples live at https://github.com/nJim/entity-bundles-examples
AI-written summary · about
chapters (14)
- 0:00Introduction to bundle classes
- 1:04Why bundle classes matter
- 3:52Object-oriented design problem
- 10:17Composition over inheritance
- 13:06Behavior strategies in Drupal
- 16:37Setting up bundle classes
- 19:05Featureable interface demo
- 22:38Teaserable trait and interfaces
- 25:04Read time behavior service
- 27:56Production example with standards
- 32:13Mechanics and implementation tips
- 36:27Design notes and best practices
- 38:10Adopting bundle classes incrementally
- 39:33Q&A: When to refactor
