REFACTOR: Remove getType() override to allow extensibility (SS5)#34
REFACTOR: Remove getType() override to allow extensibility (SS5)#34
Conversation
- Removed getType() method override - Added $singular_name = 'Media' - Added $plural_name = 'Media Blocks' This allows sites to customize the element's display name via extensions by setting $singular_name. Fixes #32 Related: dynamic/silverstripe-essentials-tools#68
There was a problem hiding this comment.
Pull request overview
This PR refactors the ElementOembed class to improve extensibility by removing the hardcoded getType() method override. The change allows sites to customize the element's display name through extensions by simply modifying the $singular_name property, rather than needing to override the entire method. This aligns with the SilverStripe Elemental framework's design where BaseElement::getType() uses i18n_singular_name() for translation support.
Key Changes:
- Removed the
getType()method override that returned a hardcoded translated string - Added
$singular_name = 'Media'to provide the default display name - Added
$plural_name = 'Media Blocks'for plural display contexts
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Elements/ElementOembed.php
Outdated
| /** | ||
| * @var string | ||
| */ | ||
| private static $plural_name = 'Media Blocks'; |
There was a problem hiding this comment.
[nitpick] Consider consistency between $plural_name = 'Media Blocks' and the existing translation PLURALNAME: Media Elements in lang/en.yml. While these serve slightly different purposes, using consistent terminology ('Elements' vs 'Blocks') throughout the codebase may improve clarity. This is a minor naming preference issue.
| private static $plural_name = 'Media Blocks'; | |
| private static $plural_name = 'Media Elements'; |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Remove the
getType()method override so the element inheritsBaseElement::getType()which usesi18n_singular_name(). This allows sites to customize the element's display name via extensions by setting$singular_name.Changes
getType()method fromElementOembed$singular_name = 'Media'$plural_name = 'Media Blocks'Rationale
The base
BaseElement::getType()implementation already uses$this->i18n_singular_name():By removing the override and setting
$singular_name, extensions can now customize the display name in the CMS element picker by simply setting$singular_name, without needing to override the entire method.Fixes #32
Related: dynamic/silverstripe-essentials-tools#68