Sylvio Posted April 22, 2011 Share Posted April 22, 2011 When I have a parent tree node where ALL the child nodes are 'hidden' and I want to add new page under that parent tree node I am getting this PHP notice: Notice: Trying to get property of non-object in C:\data\My Dropbox\www\showled.com\wire\modules\Process\ProcessPageAdd\ProcessPageAdd.module on line 100 This piece of code in 'ProcessPageAdd.module' is responsible: } else if($this->parent->numChildren > 0) { $sibling = $this->parent->children('sort=-created, limit=1')->first(); $defaultTemplateId = $sibling->template->id; } else { $defaultTemplateId = $this->parent->template->id; } So I guess it makes sense?, 'hidden' excludes pages from the children 'PageArray', but if everything is hidden then we will get an empty 'PageArray' and there will be no first() element! It's only a PHP notice, but still something that needs to be solved I think to get clean code Link to comment Share on other sites More sharing options...
Adam Kiss Posted April 22, 2011 Share Posted April 22, 2011 I think there's some code to include 'hidden' pages in your API calls, but I can't recall it right now. Other than that, if default behavior is to exclude hidden children, correct behavior for numChildren would be to return 0 if every child is hidden. Link to comment Share on other sites More sharing options...
ryan Posted April 22, 2011 Share Posted April 22, 2011 Good catch, I've updated and committed it to be this: $sibling = $this->parent->child('sort=-created, status<unpublished'); That "status<unpublished" part makes it include everything but unpublished pages. We do that rather than "status<=hidden" because 'status' is a bitwise field that might have multiple bits set (i.e. greater than the value of 'hidden'), so we have to compare to the next highest status level above 'hidden'. If that doesn't make sense, don't worry because this isn't something you would typically need in regular API usage. But if you are interested, all the status levels are listed at the top of /wire/core/Page.php. Thanks, Ryan Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now