Jump to:

23361 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Virtual Pages problems

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 299 Views
  • ho0m3s
    Avatar
    Community Member
    4 Posts

    Virtual Pages problems Link to this post

    Just started to use SilverStripe 3.1.2. The cms/framework is very powerful and gives me a lot of flexibility.
    That being said i seem to have hit a relative big problem for my current project.

    VirtualPages.

    It seems as if i can only add Virtual Pages at the root of the SiteTree. When i try to add a virtual pages in a children tree node if the properties $allowed_children is not set then i can add virtual pages. Since i want to restrict users to only being able to create Page 1, Page 2 and Virtual Page by setting the $allowed_children property of the child tree node class.
    when i create a page, at the children tree node, I get an error when selecting virtual page: "Page type "Page" not allowed as child of this parent page"

    here is the current code:

    static $allowed_children = array('*Page','CartusHolder','*VirtualPage','CartusPage');

    if I set the $allowed_children = array('SiteTree') or don't set it at all, I am then able to create Virtual Pages no problems,

    Any help would be appreciated.

  • ho0m3s
    Avatar
    Community Member
    4 Posts

    Re: Virtual Pages problems Link to this post

    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;
       }

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Virtual Pages problems Link to this post

    Could be that this was already raised as an issue on Github 8 months ago, with another possible solution.

    https://github.com/silverstripe/silverstripe-cms/issues/773

    Maybe you could have a look and possibly create a pull request?

    299 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.