silverstripe / silverstripe-framework

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

FIX Handle getting HasOneRelationFieldInterface passed as an array #11213

Closed emteknetnz closed 4 months ago

emteknetnz commented 5 months ago

Issue https://github.com/silverstripe/silverstripe-elemental/issues/1155

This fixes bugs with autoscaffolded SearchableDropdownField for has_one SiteTree relations

Replication steps

    public function getCMSCompositeValidator(): CompositeValidator
    {
        return CompositeValidator::create([RequiredFields::create(['MySiteTreeID'])]);
    }

You can leave the field blank and submit and the required fields validation won't trigger

GuySartorelli commented 5 months ago

I think the validator is working correctly - the developer should use the correct field name when setting their validator, i.e. it should be

RequiredFields::create(['MySiteTreeID'])

and not

RequiredFields::create(['MySiteTree'])
GuySartorelli commented 5 months ago

Does the bug you're fixing affect CMS 5.2? If so, please retarget to the 5.2 branch since it's fixing a bug

emteknetnz commented 4 months ago

Yeah looks like we don't need this one, I think there may have been some initial confusion with the "ID" suffix making me think things were broken when they were not

emteknetnz commented 4 months ago

Turns out we do need this one, it's required for doing a page save of an inline-block where the has_one SiteTree::class in in RequiredFields. It's NOT required for saving non-inline block's.

It showed up as a behat failure in page-save-validation.feature on https://github.com/silverstripe/silverstripe-elemental/actions/runs/8961905824/job/24613378755?pr=1178#step:12:1052