Search the Community
Showing results for tags 'manipulate'.
-
How can I change the NumChildren Label in the Tree? I am logged in as a custom user. I have an SitehelperModule where I hook in the "ProcessPageList::execute" and execute and custom Function like this which excludes all pages which the current user can't edit: And It works well, the current user gets only the Pages which he can edit, but the problem is, that the NumChridren shows that they are 5 Pages under the ParentPage and this is confusing for the customer. Can I manipulate that also? I am asking because since the PageListNumChildren is rendered by the ProcessPageList.js I dont know how to tell Processwire that it should only num the Pages which the current user can edit? if(!$this->user->isSuperuser()) $this->addHookAfter('ProcessPageList::execute', $this, 'HidePages'); public function HidePages(HookEvent $event){ // create an array with all id's of the page to exclude $uneditable_pages = new PageArray(); $the_pages = wire('pages')->find("template=activity|location|organiser|address|source|tipp"); foreach ($the_pages as $the_page) { if(!$the_page->editable()) { $uneditable_pages->add($the_page); } } $hidden = explode('|', $uneditable_pages); // make sure it's an ajax request if($this->config->ajax){ // manipulate the json returned and remove any pages found from array $json = json_decode($event->return, true); foreach($json['children'] as $key => $child){ if(in_array($child['id'],$hidden)) unset($json['children'][$key]); } $json['children'] = array_values($json['children']); $event->return = json_encode($json); } } This Code-Snippet is an mini-altered Version from Somas Code on Github
- 1 reply
-
- tree
- ProcessPageList
-
(and 2 more)
Tagged with: