Jump to content

Custom multidemensional PageArray (like a custom a PageTree)


Ivan Gretsky
 Share

Recommended Posts

I'd really like to see a PageTree object, which can hold a (whole or partial) page tree in memory. This would allow for testing stubs and similar or the api creation of a whole tree branch at once. But sadly the PageFinder class is often dependent on mysql functionality, which by now does not have feature parity with the in memory selector engine. 
 
Also a page tree object is not really like a multidimensional array, but rather a array of pages, which optionally hold another array of children. The concept this is more like e.g. the pw form api does work with it's fieldgroups.
 
I could imagine something like this:

class Tree extends WireArray{
  public function isValidItem($item) {
    return $item instanceof Branch; 
  }

  […]
}

class Branch extends Wire{
  protected $page;
  /** @var Tree $children */
  protected $children;

  function hasChildren(){};
  function getChildren(){};
  function addChild(){};

  […]
}

Edit:

Really nice could also be a base Tree class, which both a PageTree as well as e.g. the Forms API could inherit from. This would also allow for easy implementation of other (custom?) tree based constructs. Nested comments for example just came to my mind.

  • Like 3
Link to comment
Share on other sites

If you literally want to pass it to MarkupSimpleNavigation you don't need a multidimensional PageArray. You just need a normal PageArray of root pages and MSN takes care of the recursion from the root pages.

I am guessing that what Ivan is after is a Menu Builder MSN combo....as per the conversation we had....starting from here...and culminating with a PageArray here..If there was a possibility to do an in-memory $page->child = myOtherPage...(without saving)...hence assign non-native/natural children to parent menu items....that would probably solve his problem (the multidimensional bit) ...but that is not possible, If it were, don't know if getting in-memory children would work though...

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

I am guessing that what Ivan is after is a Menu Builder MSN combo....as per the conversation we had....starting from here...and culminating with a PageArray here..If there was a possibility to do an in-memory $page->child = myOtherPage...(without saving)...hence assign non-native/natural children to parent menu items....that would probably solve his problem (the multidimensional bit) ...but that is not possible, If it were, don't know if getting in-memory children would work though...

Okay, makes more sense now.

@Ivan: Seems like it would be easier to leave MSN and Menu Builder out of it. If you know the page structure you want just build a normal PHP multi-dimensional array of page IDs or page paths, then turn these IDs/paths into page objects as you iterate over the array and output the necessary markup.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...