Update getter name to getCMSCompositeValidator

This commit is contained in:
cpenny 2020-05-28 12:23:35 +12:00
parent 8ba65313e9
commit d4165db690
7 changed files with 25 additions and 16 deletions

View File

@ -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
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
respect the provided `Validator`/s and handle displaying error and success responses to the user.

View File

@ -12,20 +12,21 @@ use SilverStripe\ORM\ValidationResult;
* 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.
*
* 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']));
*
* 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']));
* }
@ -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
* @return CompositeValidator
*/

View File

@ -101,7 +101,7 @@ class DefaultFormFactory implements FormFactory
return null;
}
$compositeValidator = $context['Record']->getCompositeValidator();
$compositeValidator = $context['Record']->getCMSCompositeValidator();
// Extend validator - legacy support, will be removed in 5.0.0
foreach ($compositeValidator->getValidators() as $validator) {
@ -109,7 +109,7 @@ class DefaultFormFactory implements FormFactory
}
// Extend validator - forward support, will be supported beyond 5.0.0
$this->invokeWithExtensions('updateCompositeValidator', $compositeValidator);
$this->invokeWithExtensions('updateCMSCompositeValidator', $compositeValidator);
return $compositeValidator;
}

View File

@ -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 (!$this->getValidator()) {
$this->setValidator($record->getCompositeValidator());
$this->setValidator($record->getCMSCompositeValidator());
}
return $handler->handleRequest($request);

View File

@ -141,7 +141,7 @@ abstract class DataExtension extends Extension
*
* @param CompositeValidator $compositeValidator
*/
public function updateCompositeValidator(CompositeValidator $compositeValidator): void
public function updateCMSCompositeValidator(CompositeValidator $compositeValidator): void
{
}

View File

@ -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
*/
public function getCompositeValidator(): CompositeValidator
public function getCMSCompositeValidator(): CompositeValidator
{
$compositeValidator = new CompositeValidator();
@ -2459,14 +2467,14 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
if ($this->hasMethod('getCMSValidator')) {
Deprecation::notice(
'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());
}
// Extend validator - forward support, will be supported beyond 5.0.0
$this->invokeWithExtensions('updateCompositeValidator', $compositeValidator);
$this->invokeWithExtensions('updateCMSCompositeValidator', $compositeValidator);
return $compositeValidator;
}

View File

@ -191,8 +191,8 @@ class CompositeValidatorTest extends SapphireTest
$this->assertFalse($result->isValid());
$this->assertCount(1, $result->getMessages());
// Make sure it doesn't fail after removing validation AND has no errors (since calling validate should reset
// errors)
// Make sure it doesn't fail after removing validation AND has no errors (since calling validate should
// reset errors)
$compositeValidator->removeValidation();
$result = $form->validationResult();
$this->assertTrue($result->isValid());