ImageFormFactory extension/modification

Silverstripe 5

Question:

In the file ImageFormFactory.php (vendor/silverstripe/asset-admin/code/Forms/ImageFormFactory.php) I want to change the classes for image alignment to match those in Bootstrap 5 ie, in the example below I have changed the 4th entry “left” to “float-start”.
I need to figure out how to do this as an extension without modifying this file.
Since it’s inside a function I can’t see how to do this.

protected function getFormFieldAttributesTab($record, $context = [])
{
    $tab = parent::getFormFieldAttributesTab($record, $context);

    $alignments = [
        'leftAlone' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentLeftAlone', 'Left'),
        'center' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentCenter', 'Center'),
        'rightAlone' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentRightAlone', 'Right'),
        'float-start' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentLeft', 'Left wrap'),
        'right' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentRight', 'Right wrap'),
    ];

Looks like the only way to do that right now is to implement the updateFormFields extension hook method, get the Alignment field from the field list, and call setSource() on it with your new set of alignments.

1 Like