silverstripe / silverstripe-framework

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

DBForeignKey scaffolding uses wrong parameters to create SearchableDropdownField #11294

Closed johannesx75 closed 14 hours ago

johannesx75 commented 6 days ago

Module version(s) affected

5.2.13

Description

Auto-scaffolding for has_one form fields creates an instance of SearchableDropdownField by passing: SearchableDropdownField::create($this->name, $title, $list, $labelField)

The signature for the SearchableDropdownField constructor expects: string $name, ?string $title = null, ?DataList $source = null, mixed $value = null, string $labelField = 'Title'

So the call is missing $value. This leads to $value being set to $labelField, which is 'Title'.

Not a big deal, since the scaffolding will set the value later again. But it leads to warnings in the php log:

Could not determine value in SilverStripe|Forms|SearchableDropdownField: :getValueArray()

Since this is also affecting my idea for a solution of https://github.com/silverstripe/silverstripe-framework/issues/11293 I'll create a separate fix and pull request for this issue.

How to reproduce

Given ModelA has_one ModelB and ModelB has_many ModelA:

Check Error Log.

Possible Solution

add null as value when calling SearchableDropdownField::create

Additional Context

No response

Validations

PRs