diff --git a/model/DataExtension.php b/model/DataExtension.php index 4216c148f..d9c22d1d1 100644 --- a/model/DataExtension.php +++ b/model/DataExtension.php @@ -63,6 +63,15 @@ abstract class DataExtension extends Extension { public static function unload_extra_statics($class, $extension) { throw new Exception('unload_extra_statics gone'); } + + /** + * Hook for extension-specific validation. + * + * @param $validationResult Local validation result + * @throws ValidationException + */ + function validate(ValidationResult &$validationResult) { + } /** * Edit the given query object to support queries for this extension diff --git a/model/DataObject.php b/model/DataObject.php index 852ca21fd..fa6d0fe64 100644 --- a/model/DataObject.php +++ b/model/DataObject.php @@ -883,7 +883,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity * Validate the current object. * * By default, there is no validation - objects are always valid! However, you can overload this method in your - * DataObject sub-classes to specify custom validation. + * DataObject sub-classes to specify custom validation, or use the hook through DataExtension. * * Invalid objects won't be able to be written - a warning will be thrown and no write will occur. onBeforeWrite() * and onAfterWrite() won't get called either. @@ -894,7 +894,9 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity * @return A {@link ValidationResult} object */ protected function validate() { - return new ValidationResult(); + $result = new ValidationResult(); + $this->extend('validate', $result); + return $result; } /**