Jump to content

PageTree - pages forced to bottom of list


dfile
 Share

Recommended Posts

Hello! I'm new here and have a question:

i want to force pages to stay at the bottom of the pagetree:

pw-forum.png

I edit the ProcessPageListRenderJSON.php and it works.

class ProcessPageListRenderJSON extends ProcessPageListRender {

	protected $systemIDs = array();

	public function __construct(Page $page, PageArray $children) {

		parent::__construct($page, $children);

		$this->systemIDs = array(
			$this->config->http404PageID,
			$this->config->adminRootPageID,
			$this->config->trashPageID,
			$this->config->loginPageID,
			//system login ####################################################
			1088,
			1036,
			###################################################################
		);
	}

Is there a way to do this without hardcode it in the ProcessPageListRenderJSON.php?

Link to comment
Share on other sites

i edit the render function in ProcessPageListRenderJSON.php

	public function render() {

		$children = array();

		###############################################
		$toBottom=array(
		//system, login ###################################
			1088,
			1036,
			);

		$bottomPages=array(); // pages forced to bottom of list
		$extraPages = array(); // pages forced to bottom of list

		foreach($this->children as $page) {
			if(!$this->superuser && !$page->listable()) continue;

			if(in_array($page->id, $this->systemIDs)) {
				$extraPages[] = $page;
				continue;
			}
			
			if(in_array($page->id,$toBottom)) {
				$bottomPages[] = $page;
				continue;

			}	
	
			$child = $this->renderChild($page);
			$children[] = $child;

		}

		foreach($bottomPages as $page) { //bottomPages
			$children[] = $this->renderChild($page);
		}

		if($this->superuser) foreach($extraPages as $page) {//extraPages 
			$children[] = $this->renderChild($page);
		}

that works for me.

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.

  • Similar Content

    • By SwimToWin
      Skip the "Add New" dialog page on Page Tree and elsewhere and go directly to the resulting page that shows all page fields right away. Page creation is now improving from being a two-step to becoming a one-step process.
      Scenarios:
      When only one Template can be selected: Skip the intermediate "Add New" dialog page by adding a GUID or other temporary page name that is later renamed. Show the final editing page so user can start editing all fields right away On Save: Page name is renamed with title When multiple Templates can be selected: Ask user to select Template on clicking New (before leaving the Tree Page). Then use the "one Template" flow above. (I am aware why the Page Name is needed.)
    • By benbyf
      Hi,
      Been updating fields on a live site from my dev site to get them in synch and I noticed repeater pages visible in my pagetree on teh live site. What might I have done to have this happen? The repeater module was enabled on both sites.

    • By Xonox
      Hi,
      I updated a site from version 2. something, can't recall for sure, to version 3.0.39. All is working fine on local server. However, when I uploaded to online server, the page tree display stopped working.
      1. Whenever I try to access the page tree it gives an alert with the text: Uknown error, please try again later
      On the console I can see the following:
      GET http://mysite.com/admin/page/list?id=1&renderJSON&start=0&open=undefined&mode=actions 500 (Internal Server Error) JqueryCore.js?v=1478723146:2
      2. Whenever I try to access the page children (when editing a page) it gives an alert with the text: Uknown error, please try again later
      On the console I can see the following:
      Failed to load resource: the server responded with a status 500  http://mysite.com/admin/page/list?id=1040&renderJSON&start=0&lang=0&open=undefined&mode=actions (Internal Server Error)
       
      When I was updating, I got an error on the site config.php file. I forgot to update the $config->httpHosts for the domain in the new server, which was corrected after the update.
      The server is running PHP 5.4, MySQL 5.5.52, PW updated to 3.0.39
      Any clues?
    • By Orkun
      Hi fellows
      I have a problem with one of my hooks in processwire 3. It's a hook which manipulates the processpagelist to only show the pages which are not editable and not addable. This works fine in 2.7.3 but in pw 3 it doesn't work 100%. When the first time the ProcessPageList is rendered the hook works. Now when I open a branch and reload then it shows all pages. but when i close the branch before reload it works again and only shows the pages which are editable or addable.
       
      How it should look like:

       
      How it looks when i let the branch open and reload:

       
      PHP-Code
      $this->addHookAfter('ProcessPageList::execute', $this, 'hidePages'); public function hidePages(HookEvent $event){ $excludePages = new PageArray(); $the_pages = wire('pages')->find("template=newsletter-clinic|sender_2016|sender_2016_collab|inside-news-folder|event-clinic"); foreach ($the_pages as $the_page) { if(!$the_page->editable() && !$the_page->addable()) { $excludePages->add($the_page); } } $hidden = explode('|', $excludePages); 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); } }  
      Do you perhaps know what causes this and how to fix this?
    • By Orkun
      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
×
×
  • Create New...