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

API Add ValidationInterface to Form #11518

Merged
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
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();
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
$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
Loading