Skip to content

Commit

Permalink
APICHANGE: add validation extension hook to DataExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz committed Apr 17, 2012
1 parent cde9b31 commit 42e6ae2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions model/DataExtension.php
Expand Up @@ -63,6 +63,15 @@ static function add_to_class($class, $extensionClass, $args = null) {
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
Expand Down
6 changes: 4 additions & 2 deletions model/DataObject.php
Expand Up @@ -883,7 +883,7 @@ public function forceChange() {
* 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.
Expand All @@ -894,7 +894,9 @@ public function forceChange() {
* @return A {@link ValidationResult} object
*/
protected function validate() {
return new ValidationResult();
$result = new ValidationResult();
$this->extend('validate', $result);
return $result;
}

/**
Expand Down

0 comments on commit 42e6ae2

Please sign in to comment.