Skip to content

Update getType() to use $this->singular_name() for extensibility #31

@jsirish

Description

@jsirish

Summary

Update getType() to allow site-specific customization via extensions.

Current Implementation

public function getType()
{
    return _t(__CLASS__ . '.BlockType', 'Testimonials');
}

Proposed Change

Remove the getType() override entirely. The base BaseElement::getType() already uses $this->i18n_singular_name() which respects $singular_name:

// BaseElement::getType() - already does the right thing
public function getType()
{
    $default = $this->i18n_singular_name() ?: 'Block';
    return _t(static::class . '.BlockType', $default);
}

By removing the override, the element will inherit this behavior and allow sites to customize the display name via extensions by simply setting $singular_name.

Rationale

This pattern allows sites using these elements to customize the display name in the CMS element picker by simply setting $singular_name via an extension, rather than having to override the entire getType() method (which is not possible via extensions since PHP calls the class method directly, bypassing __call()).

Related: dynamic/silverstripe-essentials-tools#68

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions