Skip to content

REFACTOR: Remove getType() override to allow extensibility#36

Merged
jsirish merged 1 commit into5from
fix/remove-gettype-override-branch5
Dec 2, 2025
Merged

REFACTOR: Remove getType() override to allow extensibility#36
jsirish merged 1 commit into5from
fix/remove-gettype-override-branch5

Conversation

@jsirish
Copy link
Copy Markdown
Member

@jsirish jsirish commented Dec 2, 2025

Summary

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.

Changes

  • Removed the getType() method from ElementOembed
  • Added $singular_name = 'Media'
  • Added $plural_name = 'Media Blocks'

Rationale

The base BaseElement::getType() implementation already uses $this->i18n_singular_name():

public function getType()
{
    $default = $this->i18n_singular_name() ?: 'Block';
    return _t(static::class . '.BlockType', $default);
}

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

Copilot AI review requested due to automatic review settings December 2, 2025 08:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the ElementOembed class to improve extensibility by removing the hardcoded getType() method override and instead relying on the base BaseElement::getType() implementation which uses i18n_singular_name(). This allows sites 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 that returned a hardcoded translation call
  • Added $singular_name = 'Media' and $plural_name = 'Media Blocks' static properties to define default names

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +24
private static $singular_name = 'Media';

/**
* @var string
*/
private static $plural_name = 'Media Blocks';
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $singular_name and $plural_name values differ from the existing translation file values. The translation file (lang/en.yml) has SINGULARNAME: Media Element and PLURALNAME: Media Elements, but these are set to 'Media' and 'Media Blocks' respectively.

In SilverStripe, translation keys take precedence over static properties, so i18n_singular_name() will return 'Media Element' (not 'Media') and i18n_plural_name() will return 'Media Elements' (not 'Media Blocks'). This means the behavior may not match your expectations.

Consider either:

  1. Updating lang/en.yml to align with these new values, or
  2. Changing these static properties to match the existing translation values
Suggested change
private static $singular_name = 'Media';
/**
* @var string
*/
private static $plural_name = 'Media Blocks';
private static $singular_name = 'Media Element';
/**
* @var string
*/
private static $plural_name = 'Media Elements';

Copilot uses AI. Check for mistakes.
@jsirish jsirish force-pushed the fix/remove-gettype-override-branch5 branch from f623af9 to 3e4cddb Compare December 2, 2025 08:25
@jsirish jsirish requested a review from Copilot December 2, 2025 08:25
- Remove getType() method override so element inherits BaseElement::getType()
- Add $singular_name = 'Media' and $plural_name = 'Media Blocks'
- Allows extensions to customize display name via $singular_name

Fixes #32
Related: dynamic/silverstripe-essentials-tools#68
@jsirish jsirish force-pushed the fix/remove-gettype-override-branch5 branch from 3e4cddb to b4b4e11 Compare December 2, 2025 08:26
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 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.

@jsirish jsirish merged commit 66a913b into 5 Dec 2, 2025
18 checks passed
@jsirish jsirish deleted the fix/remove-gettype-override-branch5 branch December 2, 2025 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants