public function testExtensionCanBeAppliedToDataObject()
 {
     $do = new DataObject();
     $mo = new DataExtensionTest_MyObject();
     $this->assertTrue($do->hasMethod('testMethodApplied'));
     $this->assertTrue($mo->hasMethod('testMethodApplied'));
     $this->assertEquals("hello world", $mo->testMethodApplied());
     $this->assertEquals("hello world", $do->testMethodApplied());
 }
 /**
  * Determines the validator to use for the edit form
  * @example 'getCMSValidator'
  *
  * @param DataObject $file File context to generate validator from
  * @return Validator Validator object
  */
 public function getFileEditValidator(DataObject $file)
 {
     // Empty validator
     if (empty($this->fileEditValidator)) {
         return null;
     }
     // Validator instance
     if ($this->fileEditValidator instanceof Validator) {
         return $this->fileEditValidator;
     }
     // Method to call on the given file
     if ($file->hasMethod($this->fileEditValidator)) {
         return $file->{$this->fileEditValidator}();
     }
     throw new InvalidArgumentException("Invalid value for UploadField::fileEditValidator");
 }
Ejemplo n.º 3
0
 /**
  * Mark all children of the given node that match the marking filter.
  *
  * @param DataObject $node              Parent node
  * @param mixed      $context
  * @param string     $childrenMethod    The name of the instance method to call to get the object's list of children
  * @param string     $numChildrenMethod The name of the instance method to call to count the object's children
  * @return DataList
  */
 public function markChildren($node, $context = null, $childrenMethod = "AllChildrenIncludingDeleted", $numChildrenMethod = "numChildren")
 {
     if ($node->hasMethod($childrenMethod)) {
         $children = $node->{$childrenMethod}($context);
     } else {
         user_error(sprintf("Can't find the method '%s' on class '%s' for getting tree children", $childrenMethod, get_class($node)), E_USER_ERROR);
     }
     $node->markExpanded();
     if ($children) {
         foreach ($children as $child) {
             $markingMatches = $this->markingFilterMatches($child);
             if ($markingMatches) {
                 // Mark a child node as unexpanded if it has children and has not already been expanded
                 if ($child->{$numChildrenMethod}() && !$child->isExpanded()) {
                     $child->markUnexpanded();
                 } else {
                     $child->markExpanded();
                 }
                 $this->markedNodes[$child->ID] = $child;
             }
         }
     }
     return $children;
 }
 /**
  * Determines the validator to use for the edit form
  * @example 'getCMSValidator'
  *
  * @param DataObject $file File context to generate validator from
  * @return Validator Validator object
  */
 public function getFileEditValidator(DataObject $file)
 {
     // Empty validator
     if (empty($this->fileEditValidator)) {
         return null;
     }
     // Validator instance
     if ($this->fileEditValidator instanceof Validator) {
         return $this->fileEditValidator;
     }
     // Method to call on the given file
     if ($file->hasMethod($this->fileEditValidator)) {
         return $file->{$this->fileEditValidator}();
     }
     user_error("Invalid value for UploadField::fileEditValidator", E_USER_ERROR);
 }