Skip to content

Commit

Permalink
API Add ValidationInterface to Form
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 19, 2024
1 parent 313893b commit 8fa56d1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
16 changes: 2 additions & 14 deletions src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\Control\Session;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Validation\ValidationInterface;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Core\Validation\ValidationResult;
Expand All @@ -21,7 +22,6 @@
use SilverStripe\View\SSViewer;
use SilverStripe\Model\ModelData;
use SilverStripe\Forms\Validation\Validator;
use SilverStripe\Dev\Deprecation;

/**
* Base class for all forms.
Expand Down Expand Up @@ -64,7 +64,7 @@
* For example, the "URLSegment" field in a standard CMS form would be
* accessible through "admin/EditForm/field/URLSegment/FieldHolder".
*/
class Form extends ModelData implements HasRequestHandler
class Form extends ModelData implements HasRequestHandler, ValidationInterface
{
use AttributesHTML;
use FormMessage;
Expand Down Expand Up @@ -1247,18 +1247,6 @@ public function getLegend()
return $this->legend;
}

/**
* Alias of validate() for backwards compatibility.
*
* @return ValidationResult
* @deprecated 5.4.0 Use validate() instead
*/
public function validationResult()
{
Deprecation::notice('5.4.0', 'Use validate() instead');
return $this->validate();
}

/**
* Processing that occurs before a form is executed.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Forms/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ public function testValidateFormFields(array $values, bool $isValid)
}
$form = new Form(null, 'testForm', $fieldList, new FieldList([/* no actions */]));

$result = $form->validationResult();
$result = $form->validate();
$this->assertSame($isValid, $result->isValid());
$messages = $result->getMessages();
if ($isValid) {
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Forms/OptionsetFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testValidation()
$this->assertTrue($field->validate()->isValid());

// ... but should not pass "RequiredFieldsValidator" validation
$this->assertFalse($form->validationResult()->isValid());
$this->assertFalse($form->validate()->isValid());

// disabled items shouldn't validate
$field->setDisabledItems(['Five']);
Expand Down

0 comments on commit 8fa56d1

Please sign in to comment.