Merge pull request #11119 from creative-commoners/pulls/5/has-one-relation-field-interface

NEW HasOneRelationFieldInterface
This commit is contained in:
Guy Sartorelli 2024-01-31 15:22:24 +13:00 committed by GitHub
commit 05279f062c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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; namespace SilverStripe\Forms;
use SilverStripe\LinkField\Form\LinkField;
use SilverStripe\ORM\ArrayLib; use SilverStripe\ORM\ArrayLib;
/** /**
@ -117,7 +118,7 @@ class RequiredFields extends Validator
} }
} else { } else {
$stringValue = (string) $value; $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 // 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 // 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 // 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 CheckboxSetField for multiple selections through checkboxes.
* @see OptionsetField for single selections via radiobuttons. * @see OptionsetField for single selections via radiobuttons.
*/ */
class TreeDropdownField extends FormField class TreeDropdownField extends FormField implements HasOneRelationFieldInterface
{ {
protected $schemaDataType = self::SCHEMA_DATA_TYPE_SINGLESELECT; protected $schemaDataType = self::SCHEMA_DATA_TYPE_SINGLESELECT;