mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Update getter name to getCMSCompositeValidator
This commit is contained in:
parent
8ba65313e9
commit
d4165db690
@ -275,7 +275,7 @@ class MyController extends Controller
|
|||||||
|
|
||||||
In the CMS, we're not creating the forms for editing CMS records. The `Form` instance is generated for us so we cannot
|
In the CMS, we're not creating the forms for editing CMS records. The `Form` instance is generated for us so we cannot
|
||||||
call `setValidator` easily. However, a `DataObject` can provide its' own `Validator` instance/s through the
|
call `setValidator` easily. However, a `DataObject` can provide its' own `Validator` instance/s through the
|
||||||
`getCompositeValidator()` method. The CMS interfaces such as [LeftAndMain](api:SilverStripe\Admin\LeftAndMain),
|
`getCMSCompositeValidator()` method. The CMS interfaces such as [LeftAndMain](api:SilverStripe\Admin\LeftAndMain),
|
||||||
[ModelAdmin](api:SilverStripe\Admin\ModelAdmin) and [GridField](api:SilverStripe\Forms\GridField\GridField) will
|
[ModelAdmin](api:SilverStripe\Admin\ModelAdmin) and [GridField](api:SilverStripe\Forms\GridField\GridField) will
|
||||||
respect the provided `Validator`/s and handle displaying error and success responses to the user.
|
respect the provided `Validator`/s and handle displaying error and success responses to the user.
|
||||||
|
|
||||||
|
@ -12,20 +12,21 @@ use SilverStripe\ORM\ValidationResult;
|
|||||||
* Once each Validator has generated its ValidationResult, the CompositeValidator will combine these results into a
|
* Once each Validator has generated its ValidationResult, the CompositeValidator will combine these results into a
|
||||||
* single ValidationResult. This single ValidationResult is what will be returned by the CompositeValidator.
|
* single ValidationResult. This single ValidationResult is what will be returned by the CompositeValidator.
|
||||||
*
|
*
|
||||||
* You can add Validators to the CompositeValidator in any DataObject by extending the getCompositeValidator() method:
|
* You can add Validators to the CompositeValidator in any DataObject by extending the getCMSCompositeValidator()
|
||||||
|
* method:
|
||||||
*
|
*
|
||||||
* public function getCompositeValidator(): CompositeValidator
|
* public function getCMSCompositeValidator(): CompositeValidator
|
||||||
* {
|
* {
|
||||||
* $compositeValidator = parent::getCompositeValidator();
|
* $compositeValidator = parent::getCMSCompositeValidator();
|
||||||
*
|
*
|
||||||
* $compositeValidator->addValidator(RequiredFields::create(['MyRequiredField']));
|
* $compositeValidator->addValidator(RequiredFields::create(['MyRequiredField']));
|
||||||
*
|
*
|
||||||
* return $compositeValidator
|
* return $compositeValidator
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Or by implementing the updateCompositeValidator() method in a DataExtension:
|
* Or by implementing the updateCMSCompositeValidator() method in a DataExtension:
|
||||||
*
|
*
|
||||||
* public function updateCompositeValidator(CompositeValidator $compositeValidator): void
|
* public function updateCMSCompositeValidator(CompositeValidator $compositeValidator): void
|
||||||
* {
|
* {
|
||||||
* $compositeValidator->addValidator(RequiredFields::create(['AdditionalContent']));
|
* $compositeValidator->addValidator(RequiredFields::create(['AdditionalContent']));
|
||||||
* }
|
* }
|
||||||
@ -221,7 +222,7 @@ class CompositeValidator extends Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal This method may be updated to public in the future. Let us know if you feel there is a use case for it.
|
* @internal This method may be updated to public in the future. Let us know if you feel there's a use case for it
|
||||||
* @param int $key
|
* @param int $key
|
||||||
* @return CompositeValidator
|
* @return CompositeValidator
|
||||||
*/
|
*/
|
||||||
|
@ -101,7 +101,7 @@ class DefaultFormFactory implements FormFactory
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$compositeValidator = $context['Record']->getCompositeValidator();
|
$compositeValidator = $context['Record']->getCMSCompositeValidator();
|
||||||
|
|
||||||
// Extend validator - legacy support, will be removed in 5.0.0
|
// Extend validator - legacy support, will be removed in 5.0.0
|
||||||
foreach ($compositeValidator->getValidators() as $validator) {
|
foreach ($compositeValidator->getValidators() as $validator) {
|
||||||
@ -109,7 +109,7 @@ class DefaultFormFactory implements FormFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extend validator - forward support, will be supported beyond 5.0.0
|
// Extend validator - forward support, will be supported beyond 5.0.0
|
||||||
$this->invokeWithExtensions('updateCompositeValidator', $compositeValidator);
|
$this->invokeWithExtensions('updateCMSCompositeValidator', $compositeValidator);
|
||||||
|
|
||||||
return $compositeValidator;
|
return $compositeValidator;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ class GridFieldDetailForm implements GridField_URLHandler
|
|||||||
|
|
||||||
// if no validator has been set on the GridField then use the Validators from the record.
|
// if no validator has been set on the GridField then use the Validators from the record.
|
||||||
if (!$this->getValidator()) {
|
if (!$this->getValidator()) {
|
||||||
$this->setValidator($record->getCompositeValidator());
|
$this->setValidator($record->getCMSCompositeValidator());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $handler->handleRequest($request);
|
return $handler->handleRequest($request);
|
||||||
|
@ -141,7 +141,7 @@ abstract class DataExtension extends Extension
|
|||||||
*
|
*
|
||||||
* @param CompositeValidator $compositeValidator
|
* @param CompositeValidator $compositeValidator
|
||||||
*/
|
*/
|
||||||
public function updateCompositeValidator(CompositeValidator $compositeValidator): void
|
public function updateCMSCompositeValidator(CompositeValidator $compositeValidator): void
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2449,9 +2449,17 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* When extending this class and overriding this method, you will need to instantiate the CompositeValidator by
|
||||||
|
* calling parent::getCMSCompositeValidator(). This will ensure that the appropriate extension point is also
|
||||||
|
* invoked.
|
||||||
|
*
|
||||||
|
* You can also update the CompositeValidator by creating an Extension and implementing the
|
||||||
|
* updateCMSCompositeValidator(CompositeValidator $compositeValidator) method.
|
||||||
|
*
|
||||||
|
* @see CompositeValidator for examples of implementation
|
||||||
* @return CompositeValidator
|
* @return CompositeValidator
|
||||||
*/
|
*/
|
||||||
public function getCompositeValidator(): CompositeValidator
|
public function getCMSCompositeValidator(): CompositeValidator
|
||||||
{
|
{
|
||||||
$compositeValidator = new CompositeValidator();
|
$compositeValidator = new CompositeValidator();
|
||||||
|
|
||||||
@ -2459,14 +2467,14 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
if ($this->hasMethod('getCMSValidator')) {
|
if ($this->hasMethod('getCMSValidator')) {
|
||||||
Deprecation::notice(
|
Deprecation::notice(
|
||||||
'4.6',
|
'4.6',
|
||||||
'getCMSValidator() is removed in 5.0 in favour of getCompositeValidator()'
|
'getCMSValidator() is removed in 5.0 in favour of getCMSCompositeValidator()'
|
||||||
);
|
);
|
||||||
|
|
||||||
$compositeValidator->addValidator($this->getCMSValidator());
|
$compositeValidator->addValidator($this->getCMSValidator());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extend validator - forward support, will be supported beyond 5.0.0
|
// Extend validator - forward support, will be supported beyond 5.0.0
|
||||||
$this->invokeWithExtensions('updateCompositeValidator', $compositeValidator);
|
$this->invokeWithExtensions('updateCMSCompositeValidator', $compositeValidator);
|
||||||
|
|
||||||
return $compositeValidator;
|
return $compositeValidator;
|
||||||
}
|
}
|
||||||
|
@ -191,8 +191,8 @@ class CompositeValidatorTest extends SapphireTest
|
|||||||
$this->assertFalse($result->isValid());
|
$this->assertFalse($result->isValid());
|
||||||
$this->assertCount(1, $result->getMessages());
|
$this->assertCount(1, $result->getMessages());
|
||||||
|
|
||||||
// Make sure it doesn't fail after removing validation AND has no errors (since calling validate should reset
|
// Make sure it doesn't fail after removing validation AND has no errors (since calling validate should
|
||||||
// errors)
|
// reset errors)
|
||||||
$compositeValidator->removeValidation();
|
$compositeValidator->removeValidation();
|
||||||
$result = $form->validationResult();
|
$result = $form->validationResult();
|
||||||
$this->assertTrue($result->isValid());
|
$this->assertTrue($result->isValid());
|
||||||
|
Loading…
Reference in New Issue
Block a user