1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-08 07:47:00 +02:00

Update PageList to add new classes to items: 'PageListNotPublic' when page is not public for viewing to guest user, 'PageListNoFile' when page has no template file. Plus some other minor optimizationsin while there.

This commit is contained in:
Ryan Cramer
2024-04-03 10:24:48 -04:00
parent e0f67aa55e
commit 37416f8bcc

View File

@@ -19,6 +19,12 @@ class ProcessPageListRenderJSON extends ProcessPageListRender {
*/ */
protected $systemIDs = array(); protected $systemIDs = array();
/**
* @var Role|null
*
*/
protected $guestRole = null;
/** /**
* Wired to ProcessWire * Wired to ProcessWire
* *
@@ -51,11 +57,11 @@ class ProcessPageListRenderJSON extends ProcessPageListRender {
$outputFormatting = $page->outputFormatting; $outputFormatting = $page->outputFormatting;
$page->setOutputFormatting(true); $page->setOutputFormatting(true);
$class = '';
$type = ''; $type = '';
$note = ''; $note = '';
$label = ''; $label = '';
$icons = array(); $icons = array();
$class = array();
$id = $page->id; $id = $page->id;
if(isset($this->systemIDs[$id])) { if(isset($this->systemIDs[$id])) {
@@ -70,22 +76,36 @@ class ProcessPageListRenderJSON extends ProcessPageListRender {
// if label is not overridden by a language pack, make $label blank to use the page title instead // if label is not overridden by a language pack, make $label blank to use the page title instead
if(in_array($label, array('Trash', 'Admin', '404 Page Not Found'))) $label = ''; if(in_array($label, array('Trash', 'Admin', '404 Page Not Found'))) $label = '';
} }
if(!$page->template->filenameExists()) {
$class[] = 'PageListNoFile';
}
$accessParent = $page->getAccessParent();
if($accessParent->id) {
if(!$this->guestRole) $this->guestRole = $this->wire()->roles->getGuestRole();
$accessTemplate = $accessParent->template;
$accessGuest = $accessTemplate ? $accessTemplate->hasRole($this->guestRole) : false;
if(!$accessGuest) $class[] = 'PageListNotPublic';
if($page->getAccessParent() === $page && $page->parent->id) { if($accessParent === $page && $page->parent->id) {
$accessTemplate = $page->getAccessTemplate(); $parentAccessTemplate = $page->parent->getAccessTemplate();
if($accessTemplate && $accessTemplate->hasRole('guest')) { if(!$parentAccessTemplate) {
$accessTemplate = $page->parent->getAccessTemplate(); // ok
if($accessTemplate && !$accessTemplate->hasRole('guest') && !$page->isTrash()) { } else if($accessGuest) {
$class .= ' PageListAccessOn'; if(!$parentAccessTemplate->hasRole('guest') && !$page->isTrash()) {
$icons[] = 'key fa-flip-horizontal'; $class[] = 'PageListAccessOn';
$icons[] = 'key flip-horizontal';
}
} else {
if($parentAccessTemplate->hasRole('guest')) {
$class[] = 'PageListAccessOff';
$icons[] = 'key';
}
} }
} else { }
$accessTemplate = $page->parent->getAccessTemplate();
if($accessTemplate && $accessTemplate->hasRole('guest')) {
$class .= ' PageListAccessOff';
$icons[] = 'key';
}
}
} }
if($id == $config->trashPageID) { if($id == $config->trashPageID) {
@@ -117,10 +137,10 @@ class ProcessPageListRenderJSON extends ProcessPageListRender {
$numTotal = strpos($this->qtyType, 'total') !== false ? $page->numDescendants : $numChildren; $numTotal = strpos($this->qtyType, 'total') !== false ? $page->numDescendants : $numChildren;
} }
if(!$label) $label = $this->getPageLabel($page); if($label === '') $label = $this->getPageLabel($page);
if(count($icons)) foreach($icons as $icon) { foreach($icons as $icon) {
$label .= "<i class='PageListStatusIcon fa fa-fw fa-$icon'></i>"; $label .= wireIconMarkup("$icon fw PageListStatusIcon");
} }
$a = array( $a = array(
@@ -131,11 +151,11 @@ class ProcessPageListRenderJSON extends ProcessPageListRender {
'numTotal' => $numTotal, 'numTotal' => $numTotal,
'path' => $page->template->slashUrls || $id == 1 ? $page->path() : rtrim($page->path(), '/'), 'path' => $page->template->slashUrls || $id == 1 ? $page->path() : rtrim($page->path(), '/'),
'template' => $page->template->name, 'template' => $page->template->name,
//'rm' => $this->superuser && $page->trashable(),
'actions' => array_values($this->getPageActions($page)), 'actions' => array_values($this->getPageActions($page)),
//'rm' => $this->superuser && $page->trashable(),
); );
if($class) $a['addClass'] = trim($class); if(count($class)) $a['addClass'] = implode(' ', $class);
if($type) $a['type'] = $type; if($type) $a['type'] = $type;
if($note) $a['note'] = $note; if($note) $a['note'] = $note;