Skip to content
This repository
Browse code

APICHANGE: add validation extension hook to DataExtension

  • Loading branch information...
commit 42e6ae2cdfa625a29111c3b314d2c9a5710ee90e 1 parent cde9b31
Mateusz U authored April 13, 2012
9  model/DataExtension.php
@@ -63,6 +63,15 @@ static function add_to_class($class, $extensionClass, $args = null) {
63 63
 	public static function unload_extra_statics($class, $extension) {
64 64
 		throw new Exception('unload_extra_statics gone');
65 65
 	}
  66
+
  67
+	/**
  68
+	 * Hook for extension-specific validation.
  69
+	 *
  70
+	 * @param $validationResult Local validation result
  71
+	 * @throws ValidationException
  72
+	 */
  73
+	function validate(ValidationResult &$validationResult) {
  74
+	}
66 75
 	
67 76
 	/**
68 77
 	 * Edit the given query object to support queries for this extension
6  model/DataObject.php
@@ -883,7 +883,7 @@ public function forceChange() {
883 883
 	 * Validate the current object.
884 884
 	 *
885 885
 	 * By default, there is no validation - objects are always valid!  However, you can overload this method in your
886  
-	 * DataObject sub-classes to specify custom validation.
  886
+	 * DataObject sub-classes to specify custom validation, or use the hook through DataExtension.
887 887
 	 * 
888 888
 	 * Invalid objects won't be able to be written - a warning will be thrown and no write will occur.  onBeforeWrite()
889 889
 	 * and onAfterWrite() won't get called either.
@@ -894,7 +894,9 @@ public function forceChange() {
894 894
 	 * @return A {@link ValidationResult} object
895 895
 	 */
896 896
 	protected function validate() {
897  
-		return new ValidationResult();
  897
+		$result = new ValidationResult();
  898
+		$this->extend('validate', $result);
  899
+		return $result;
898 900
 	}
899 901
 
900 902
 	/**

0 notes on commit 42e6ae2

Please sign in to comment.
Something went wrong with that request. Please try again.