silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
721 stars 821 forks source link

DBHTMLText should instantiate HTMLEditorField via injector using ::create(). #9143

Open patricknelson opened 5 years ago

patricknelson commented 5 years ago

Affected Version

All versions of SS 4.x. (and 3.x but this cannot be fixed there due to maintenance schedule)

Description

When automatically generating an editor form for DataObject's for an HTMLText type, SilverStripe will instantiate HTMLEditorField directly using the new keyword instead of passing it through the Injector via ::create() like it should.

See: https://github.com/silverstripe/silverstripe-framework/blob/3e90fdf42f3306d9de739edee807175538f10d88/src/ORM/FieldType/DBHTMLText.php#L206

Relates to https://github.com/silverstripe/silverstripe-cms/pull/2050

Steps to Reproduce

  1. Configure your own custom HTML editor field class called CustomHtmlEditorField that extends HtmlEditorField and configure it in the injector, e.g.
    Injector:
    HtmlEditorField:
    class: CustomHtmlEditorField
  2. Create a generic DataObject with a 'ExampleContent' => 'HTMLText' field.
  3. In the CMS when you begin editing the DataObject you created, the default framework HtmlEditorField is instantiated and used in the form instead of your custom editor CustomHtmlEditorField.
patricknelson commented 5 years ago

QQ: When issuing a PR, should this be submitted against the latest dot release (e.g. 4.4) or against 4?

ScopeyNZ commented 5 years ago

We usually consider these "should use injector" changes as non-breaking bug-fixes. You should be fine to target 4.4 (or 4.3 if you want to affect any future patch releases for the 4.3 line too).