Revert Casting for FormField Title to `HTMLFragment`

Silverstripe Version: 4.4.0

Question:

Is there a way to revert the casting of FormField titles from ‘Text’ to ‘HTMLFragment’ so that they behave like they did in SS3?

I have a couple of SS3 projects where this would make it so much easier to upgrade to SS4.

I’ve tired using an extension, but no joy:

class FormFieldExtension extends Extension {
    private static $casting = array(
        'Title' => 'HTMLFragment',
    );
}

Were field titles not escaped in SS3? That seems like a bug, but now that you mention it I think I have relied on that quirk before, maybe not on titles but for including formatting in descriptions.

According to the docs though, ->setTitle() expects escaped HTML… which seems weird (and could be wrong). I wonder if the constructor expects an unescaped string but the method expects HTML?

A bit hacky but if the docs are right, could you modify your TextField calls something like this? Or would that be too much re-work?

TextField::Create('SomeField', 'My plain text title')->setTitle('My <b><i>fabulous</i></b> title');

Thanks @JonoM, although perhaps it’s the docs that haven’t been updated as using setTitle doesn’t seem to help, unfortunately.

It is possible to update them on an individual basis to:

TextField::Create('SomeField', DBField::create_field('HTMLFragment','My <b><i>fabulous</i></b> title''));

But there are some projects of mine where I’d prefer to be able to change it globally when updating to SilverStripe 4.