Skip to content

Commit

Permalink
Merge pull request #11119 from creative-commoners/pulls/5/has-one-rel…
Browse files Browse the repository at this point in the history
…ation-field-interface

NEW HasOneRelationFieldInterface
  • Loading branch information
GuySartorelli authored Jan 31, 2024
2 parents 1eadc84 + 9d335f7 commit 05279f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Forms/HasOneRelationFieldInterface.php
Original file line number Diff line number Diff line change
@@ -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
{
}
3 changes: 2 additions & 1 deletion src/Forms/RequiredFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Forms;

use SilverStripe\LinkField\Form\LinkField;
use SilverStripe\ORM\ArrayLib;

/**
Expand Down Expand Up @@ -117,7 +118,7 @@ public function php($data)
}
} 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
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/TreeDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* @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;

Expand Down

0 comments on commit 05279f0

Please sign in to comment.