NEW HasOneRelationFieldInterface

This commit is contained in:
Steve Boyd 2024-01-31 10:34:25 +13:00
parent 1eadc84a22
commit 9d335f73d6
3 changed files with 14 additions and 2 deletions

View File

@ -0,0 +1,11 @@
<?php
namespace SilverStripe\Forms;
/**
* Added to form fields whose values are the ID of a has_one relation
* This is used in RequiredFields validation to check if the value is set
*/
interface HasOneRelationFieldInterface
{
}

View File

@ -2,6 +2,7 @@
namespace SilverStripe\Forms;
use SilverStripe\LinkField\Form\LinkField;
use SilverStripe\ORM\ArrayLib;
/**
@ -117,7 +118,7 @@ class RequiredFields extends Validator
}
} else {
$stringValue = (string) $value;
if ($formField instanceof TreeDropdownField) {
if (is_a($formField, HasOneRelationFieldInterface::class)) {
// test for blank string as well as '0' because older versions of silverstripe/admin FormBuilder
// forms created using redux-form would have a value of null for unsaved records
// the null value will have been converted to '' by the time it gets to this point

View File

@ -55,7 +55,7 @@ use SilverStripe\ORM\Hierarchy\MarkedSet;
* @see CheckboxSetField for multiple selections through checkboxes.
* @see OptionsetField for single selections via radiobuttons.
*/
class TreeDropdownField extends FormField
class TreeDropdownField extends FormField implements HasOneRelationFieldInterface
{
protected $schemaDataType = self::SCHEMA_DATA_TYPE_SINGLESELECT;