Quantcast
Channel:
Viewing all articles
Browse latest Browse all 4235

Re: Virtual Pages problems

$
0
0

the fix is to update the sitetree.php method validate and add an if statement.

look for this:
if(!in_array($subject->ClassName, $allowed)) {
...
}

and wrap it in a parent if statement like this:
if(!($this instanceof VirtualPage)){
if(!in_array($subject->ClassName, $allowed)) {
.....
}
}

public function validate() {
      $result = parent::validate();

      // Allowed children validation
      $parent = $this->getParent();
      if($parent && $parent->exists()) {
         // No need to check for subclasses or instanceof, as allowedChildren() already
         // deconstructs any inheritance trees already.
         $allowed = $parent->allowedChildren();
         $subject = ($this instanceof VirtualPage) ? $this->CopyContentFrom() : $this;
      
      

         if(!($this instanceof VirtualPage)){//UPDATED BY MARK using solution found on https://github.com/silverstripe/silverstripe-cms/issues/773
            if(!in_array($subject->ClassName, $allowed)) {
               
               $result->error(
                  _t(
                     'SiteTree.PageTypeNotAllowed',
                     'Page type "{type}" not allowed as child of this parent page',
                     array('type' => $subject->i18n_singular_name())
                  ),
                  'ALLOWED_CHILDREN'
               );
            }
         }
         
      }
      
      // "Can be root" validation
      if(!$this->stat('can_be_root') && !$this->ParentID) {
         $result->error(
            _t(
               'SiteTree.PageTypNotAllowedOnRoot',
               'Page type "{type}" is not allowed on the root level',
               array('type' => $this->i18n_singular_name())
            ),
            'CAN_BE_ROOT'
         );
      }
      //print_r($result);
      //exit;
      return $result;
   }


Posted to: Virtual Pages problems | Show Thread | Post Reply


Viewing all articles
Browse latest Browse all 4235

Trending Articles