Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Impossible to create nested Virtual Pages where parent restricts allowed_children #773

Closed
spronkey opened this Issue Jun 16, 2013 · 2 comments

Comments

Projects
None yet
4 participants

I encountered this situation with subsites, but it occurs with standard VirtualPages as well.

Steps:

  1. You need to have a nested page hierarchy somewhere you wish to duplicate with virtualpages. This hierarchy needs to have the parent restrict $allowed_children i.e. = array('SomeOtherPageTypeOnly');
  2. Create root VirtualPage, point to top level of existing hierarchy (works fine)
  3. Attempt to create virtual page beneath the virtual page created above
  4. Error occurs (type Page not allowed here)

What's going on:

  1. Virtual Pages are first created without a CopyContentFromID target.
  2. When SiteTree::validate() is called when saving the nested VPage (in 3), that VirtualPage's CopyContentFrom() returns a new SiteTree(), which obviously does not meet the allowed page type of SomeOtherPageTypeOnly, and fails the check.

Potential fix:
SiteTree::validate() needs to check whether the subject actually exists. It's not good enough to check $this->isEmpty() either, because the validation() gets run twice on save - once where isEmpty is true, and once where isEmpty is false, but before the CopyContentFromID gets set (and thus validation fails again).

For example, on SiteTree:1529

$subject = ($this instanceof VirtualPage) ? $this->CopyContentFrom() : $this;
if(!($this instanceof VirtualPage) || $subject->Exists()) {
  // now check allowed page types
}

Just ran into the same issue, fixed by above code in line 1547. This fix should get into core
Framework 3.1.2, CMS 3.1.2

<?php
class StoryPage extends Page {
    private static $allowed_children = array('StoryPage', 'VirtualPage');
}

Create a Virtual Page underneath some StoryPage and receive the error

Page type "Page" not allowed as child of this parent page

@simonwelsh simonwelsh added the 3.1 label Mar 16, 2014

@antons- antons- pushed a commit to antons-/silverstripe-cms that referenced this issue Sep 15, 2014

Anton Smith Issue #773 - $allowed_children not allowing nested virtual pages 5532f80

@antons- antons- pushed a commit to antons-/silverstripe-cms that referenced this issue Sep 17, 2014

Anton Smith Issue #773 - $allowed_children not allowing nested virtual pages
Additional check to see if a 'VirtualPage' has a page attached to it
9d997fb

@kinglozzer kinglozzer added a commit to kinglozzer/silverstripe-cms that referenced this issue Aug 6, 2015

@kinglozzer Anton Smith + kinglozzer Issue #773 - $allowed_children not allowing nested virtual pages
Additional check to see if a 'VirtualPage' has a page attached to it
c668455

@kinglozzer kinglozzer added a commit to kinglozzer/silverstripe-cms that referenced this issue Aug 6, 2015

@kinglozzer kinglozzer Merge pull request #1100 from antons-/773-nested-virtual-pages-allowe…
…d_children

* antons--773-nested-virtual-pages-allowed_children:
  Issue #773 - $allowed_children not allowing nested virtual pages
718503e
Owner

kinglozzer commented Aug 6, 2015

Closed via c668455

@kinglozzer kinglozzer closed this Aug 6, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment