REFACTOR: Remove getType() override to allow extensibility#20
Conversation
Remove the getType() method override so the element inherits BaseElement::getType() which uses i18n_singular_name(). This allows sites to customize the element's display name via extensions by setting $singular_name. Also updated $singular_name from 'Embedded Code Element' to 'Embedded Code' and $plural_name to 'Embedded Code Blocks' for better consistency with other elements. Fixes #19
There was a problem hiding this comment.
Pull request overview
This PR refactors ElementEmbeddedCode to improve extensibility by removing the hardcoded getType() override and relying on the base class implementation that uses i18n_singular_name(). This allows developers to customize the element's display name through extensions by simply setting the $singular_name property rather than overriding the entire method.
Key Changes:
- Removed the
getType()method override to leverageBaseElement::getType() - Updated
$singular_nameto'Embedded Code'(from'Embedded Code Element') to maintain the same display name - Updated
$plural_nameto'Embedded Code Blocks'(from'Embedded Code Elements')
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private static $singular_name = 'Embedded Code'; | ||
|
|
||
| /** | ||
| * @var string | ||
| */ | ||
| private static $plural_name = 'Embedded Code Elements'; | ||
| private static $plural_name = 'Embedded Code Blocks'; |
There was a problem hiding this comment.
The plural name 'Embedded Code Blocks' is inconsistent with the singular name 'Embedded Code'. Typically, the plural should be the plural form of the singular. Consider changing $plural_name to 'Embedded Codes' to maintain consistency, or if you want to emphasize the block nature, consider changing $singular_name to 'Embedded Code Block' so that the plural follows naturally as 'Embedded Code Blocks'.
|
The plural naming convention |
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 fromElementEmbeddedCode$singular_namefrom'Embedded Code Element'to'Embedded Code'$plural_namefrom'Embedded Code Elements'to'Embedded Code Blocks'Rationale
The base
BaseElement::getType()implementation already uses$this->i18n_singular_name():By removing the override, 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 #19
Related: dynamic/silverstripe-essentials-tools#68