Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW HasOneRelationFieldInterface #11119

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading