diff --git a/wire/modules/Process/ProcessPageList/ProcessPageList.module b/wire/modules/Process/ProcessPageList/ProcessPageList.module index 27fcff35..304066aa 100644 --- a/wire/modules/Process/ProcessPageList/ProcessPageList.module +++ b/wire/modules/Process/ProcessPageList/ProcessPageList.module @@ -21,6 +21,8 @@ * @property bool|int $useBookmarks Allow use of PageList bookmarks? * @property bool|int $useTrash Allow non-superusers to use Trash? * @property string $qtyType What to show in children quantity label? 'children', 'total', 'children/total', 'total/children', or 'id' + * @property array $hidePages Page IDs to hide from root page list. (3.0.202+) + * @property array $hidePagesNot Values of 'debug', 'advanced', 'superuser' to not hide above pages when in that state. (3.0.202+) * * @method string ajaxAction($action) * @method PageArray find($selectorString, Page $page) @@ -120,7 +122,8 @@ class ProcessPageList extends Process implements ConfigurableModule { $this->set('useTrash', false); $this->set('bookmarks', array()); $this->set('qtyType', ''); - + parent::set('hidePages', array(404)); + parent::set('hidePagesNot', array()); parent::__construct(); } @@ -373,6 +376,7 @@ class ProcessPageList extends Process implements ConfigurableModule { $renderer->setLabel('trash', $this->trashLabel); $renderer->setUseTrash($this->useTrash || $superuser); $renderer->setQtyType($this->qtyType); + $renderer->setHidePages($this->hidePages, $this->hidePagesNot); return $renderer; } @@ -477,7 +481,7 @@ class ProcessPageList extends Process implements ConfigurableModule { * */ public function set($key, $value) { - if($key == 'id') { // allow setting by other modules, overrides $_GET value of ID + if($key === 'id') { // allow setting by other modules, overrides $_GET value of ID $this->id = (int) $value; return $this; } @@ -691,8 +695,30 @@ class ProcessPageList extends Process implements ConfigurableModule { /** @var InputfieldWrapper $fields */ $fields = $this->wire(new InputfieldWrapper()); - /** @var Modules $modules */ - $modules = $this->wire('modules'); + $modules = $this->wire()->modules; + + /** @var InputfieldPageListSelectMultiple $field */ + $field = $modules->get('InputfieldPageListSelectMultiple'); + $field->attr('name', 'hidePages'); + $field->label = $this->_('Hide these pages in page list(s)'); + $field->description = $this->_('Select one or more pages that you do not want to appear in page list(s).'); + $field->val($this->hidePages); + $field->columnWidth = 60; + $field->icon = 'eye-slash'; + $fields->add($field); + + /** @var InputfieldCheckboxes $field */ + $field = $modules->get('InputfieldCheckboxes'); + $field->attr('name', 'hidePagesNot'); + $field->label = $this->_('Except when (AND condition)'); + $field->addOption('debug', $this->_('System in debug mode')); + $field->addOption('advanced', $this->_('System in advanced mode')); + $field->addOption('superuser', $this->_('Current user is superuser')); + $field->showIf = 'hidePages.count>0'; + $field->val($this->hidePagesNot); + $field->icon = 'eye-slash'; + $field->columnWidth = 40; + $fields->add($field); /** @var InputfieldCheckbox $field */ $field = $modules->get('InputfieldCheckbox'); diff --git a/wire/modules/Process/ProcessPageList/ProcessPageListRender.php b/wire/modules/Process/ProcessPageList/ProcessPageListRender.php index cee3e5ba..8e400e24 100644 --- a/wire/modules/Process/ProcessPageList/ProcessPageListRender.php +++ b/wire/modules/Process/ProcessPageList/ProcessPageListRender.php @@ -79,6 +79,24 @@ abstract class ProcessPageListRender extends Wire { */ protected $useTrash = false; + /** + * Page IDs to hide in page list (both keys and values are page IDs) + * + * @var array + * + */ + protected $hidePages = array(); + + /** + * Do not hide above pages when current state matches value [ 'debug', 'advanced', 'superuser' ] + * + * Both keys and values are the same. + * + * @var array + * + */ + protected $hidePagesNot = array(); + /** * @var string Quantity type * @@ -220,6 +238,24 @@ abstract class ProcessPageListRender extends Wire { $this->pageLabelField = $pageLabelField; } + /** + * Set when pages should be hidden in page list + * + * @param array $hidePages IDs of pages that should be hidden + * @param array $hidePagesNot Do not hide pages when state matches one or more of 'debug', 'advanced', 'superuser' + * + */ + public function setHidePages($hidePages, $hidePagesNot) { + if(is_array($hidePages)) { + $this->hidePages = array(); + foreach($hidePages as $id) $this->hidePages[(int) $id] = (int) $id; + } + if(is_array($hidePagesNot)) { + $this->hidePagesNot = array(); + foreach($hidePagesNot as $state) $this->hidePagesNot[$state] = $state; + } + } + /** * Set the quantity type * diff --git a/wire/modules/Process/ProcessPageList/ProcessPageListRenderJSON.php b/wire/modules/Process/ProcessPageList/ProcessPageListRenderJSON.php index c63909d4..2f6ebb42 100644 --- a/wire/modules/Process/ProcessPageList/ProcessPageListRenderJSON.php +++ b/wire/modules/Process/ProcessPageList/ProcessPageListRenderJSON.php @@ -26,12 +26,15 @@ class ProcessPageListRenderJSON extends ProcessPageListRender { */ public function wired() { $config = $this->config; - $this->systemIDs = array( + $systemIDs = array( $config->http404PageID, $config->adminRootPageID, $config->trashPageID, $config->loginPageID, ); + foreach($systemIDs as $id) { + $this->systemIDs[$id] = $id; + } parent::wired(); } @@ -43,6 +46,8 @@ class ProcessPageListRenderJSON extends ProcessPageListRender { * */ public function renderChild(Page $page) { + + $config = $this->wire()->config; $outputFormatting = $page->outputFormatting; $page->setOutputFormatting(true); @@ -51,14 +56,15 @@ class ProcessPageListRenderJSON extends ProcessPageListRender { $note = ''; $label = ''; $icons = array(); + $id = $page->id; - if(in_array($page->id, $this->systemIDs)) { + if(isset($this->systemIDs[$id])) { $type = 'System'; - if($page->id == $this->config->http404PageID) { + if($id == $config->http404PageID) { $label = $this->_('404 Page Not Found'); // Label for '404 Page Not Found' page in PageList // Overrides page title if used - } else if($page->id == $this->config->adminRootPageID) { + } else if($id == $config->adminRootPageID) { $label = $this->_('Admin'); // Label for 'Admin' page in PageList // Overrides page title if used - } else if($page->id == $this->config->trashPageID && isset($this->actionLabels['trash'])) { + } else if($id == $config->trashPageID && isset($this->actionLabels['trash'])) { $label = $this->actionLabels['trash']; // Label for 'Trash' page in PageList // Overrides page title if used } // if label is not overridden by a language pack, make $label blank to use the page title instead @@ -82,7 +88,7 @@ class ProcessPageListRenderJSON extends ProcessPageListRender { } } - if($page->id == $this->config->trashPageID) { + if($id == $config->trashPageID) { $note = ''; if($this->superuser) { $note = "< " . $this->_("Trash open: drag pages below here to trash them"); // Message that appears next to the Trash page when open @@ -97,7 +103,7 @@ class ProcessPageListRenderJSON extends ProcessPageListRender { } } if(strpos($this->qtyType, 'total') !== false) { - $numTotal = $this->wire('pages')->trasher()->getTrashTotal(); + $numTotal = $this->wire()->pages->trasher()->getTrashTotal(); } else { $numTotal = $numChildren; } @@ -116,12 +122,12 @@ class ProcessPageListRenderJSON extends ProcessPageListRender { } $a = array( - 'id' => $page->id, + 'id' => $id, 'label' => $label, 'status' => $page->status, 'numChildren' => $numChildren, 'numTotal' => $numTotal, - 'path' => $page->template->slashUrls || $page->id == 1 ? $page->path() : rtrim($page->path(), '/'), + 'path' => $page->template->slashUrls || $id == 1 ? $page->path() : rtrim($page->path(), '/'), 'template' => $page->template->name, //'rm' => $this->superuser && $page->trashable(), 'actions' => array_values($this->getPageActions($page)), @@ -152,13 +158,26 @@ class ProcessPageListRenderJSON extends ProcessPageListRender { $id404 = $config->http404PageID; foreach($this->children as $page) { + if(!$this->superuser && !$page->listable()) continue; + + $id = $page->id; - if($page->id == $id404 && !$this->superuser) { + if($id == $id404 && !$this->superuser) { // allow showing 404 page, only if it's editable if(!$page->editable()) continue; - } else if(in_array($page->id, $this->systemIDs)) { - if($this->superuser) $extraPages[$page->id] = $page; + + } else if(isset($this->hidePages[$id]) && $id != $idTrash && $id != 1) { + $states = array(); + foreach($this->hidePagesNot as $state) { + if($state === 'debug' && $config->debug) $states[] = $state; + if($state === 'advanced' && $config->advanced) $states[] = $state; + if($state === 'superuser' && $this->superuser) $states[] = $state; + } + if(count($states) === count($this->hidePagesNot)) continue; + + } else if(isset($this->systemIDs[$id])) { + if($this->superuser) $extraPages[$id] = $page; continue; } @@ -168,7 +187,7 @@ class ProcessPageListRenderJSON extends ProcessPageListRender { // add in the trash page if not present and allowed if($this->page->id === 1 && !$this->superuser && !isset($extraPages[$idTrash]) && $this->getUseTrash()) { - $pageTrash = $this->wire('pages')->get($idTrash); + $pageTrash = $this->wire()->pages->get($idTrash); if($pageTrash->id && $pageTrash->listable()) { $extraPages[$pageTrash->id] = $pageTrash; }