mirror of
https://github.com/processwire/processwire.git
synced 2025-08-11 17:24:46 +02:00
Add support for feature requested in processwire/processwire-issues#1408 - make ProcessPageType labels indicate page status (hidden, unpublished) in admin drop down menus
This commit is contained in:
@@ -437,17 +437,19 @@ abstract class Process extends WireData implements Module {
|
||||
'iconKey' => 'icon', // property/field containing icon, when applicable
|
||||
'icon' => '', // default icon to use for items
|
||||
'classKey' => '_class', // property to pull additional class names from. Example class: "separator" or "highlight"
|
||||
'labelClassKey' => '_labelClass', // property to pull class for element to wrap label
|
||||
'sort' => true, // automatically sort items A-Z?
|
||||
'getArray' => false, // makes this method return an array rather than JSON
|
||||
);
|
||||
);
|
||||
|
||||
$options = array_merge($defaults, $options);
|
||||
$moduleInfo = $this->modules->getModuleInfo($this);
|
||||
if(empty($moduleInfo['useNavJSON'])) {
|
||||
throw new Wire404Exception('No JSON nav available', Wire404Exception::codeSecondary);
|
||||
}
|
||||
|
||||
$page = $this->wire('page');
|
||||
|
||||
$sanitizer = $this->wire()->sanitizer;
|
||||
$page = $this->wire()->page;
|
||||
$data = array(
|
||||
'url' => $page->url,
|
||||
'label' => $this->_((string) $page->get('title|name')),
|
||||
@@ -482,17 +484,29 @@ abstract class Process extends WireData implements Module {
|
||||
}
|
||||
if(empty($icon) && $options['icon']) $icon = $options['icon'];
|
||||
$_label = $label;
|
||||
$label = $this->wire('sanitizer')->entities1($label);
|
||||
$label = $sanitizer->entities1($label);
|
||||
while(isset($data['list'][$_label])) $_label .= "_";
|
||||
|
||||
if($options['itemLabel2']) {
|
||||
$label2 = is_array($item) ? $item[$options['itemLabel2']] : $item->{$options['itemLabel2']};
|
||||
if(strlen($label2)) {
|
||||
$label2 = $this->wire('sanitizer')->entities1($label2);
|
||||
$label2 = $sanitizer->entities1($label2);
|
||||
$label .= " <small>$label2</small>";
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($options['labelClassKey'])) {
|
||||
if(is_array($item)) {
|
||||
$labelClass = isset($item[$options['labelClassKey']]) ? $item[$options['labelClassKey']] : '';
|
||||
} else {
|
||||
$labelClass = is_object($item) ? $item->{$options['labelClassKey']} : '';
|
||||
}
|
||||
if($labelClass) {
|
||||
$labelClass = $sanitizer->entities($labelClass);
|
||||
$label = "<span class='$labelClass'>$label</span>";
|
||||
}
|
||||
}
|
||||
|
||||
$data['list'][$_label] = array(
|
||||
'url' => str_replace(array('{id}', '{name}'), array($id, $name), $options['edit']),
|
||||
'label' => $label,
|
||||
|
@@ -231,6 +231,10 @@ class ProcessPageType extends Process implements ConfigurableModule, WirePageEdi
|
||||
$pages = $this->pages->find("start=$start, limit=$limit");
|
||||
foreach($pages as $page) {
|
||||
if(!$page->editable()) $pages->remove($page);
|
||||
$status = ucwords($page->statusStr);
|
||||
if($status) $page->setQuietly('_labelClass', trim(str_replace(' ', ' PageListStatus', " $status")));
|
||||
$icon = $page->getIcon();
|
||||
if($icon) $page->setQuietly('_labelIcon', $icon);
|
||||
}
|
||||
$options['items'] = $pages;
|
||||
$parent = $this->pages->getParent();
|
||||
@@ -242,9 +246,49 @@ class ProcessPageType extends Process implements ConfigurableModule, WirePageEdi
|
||||
$options['edit'] = "edit/?id={id}";
|
||||
}
|
||||
if(!isset($options['itemLabel'])) $options['itemLabel'] = $this->jsonListLabel;
|
||||
if(!isset($options['iconKey'])) $options['iconKey'] = '_labelIcon';
|
||||
|
||||
|
||||
return parent::___executeNavJSON($options);
|
||||
}
|
||||
|
||||
public function x___executeNavJSON(array $options = array()) {
|
||||
|
||||
if(!isset($options['items'])) {
|
||||
$sanitizer = $this->wire()->sanitizer;
|
||||
$input = $this->wire()->input;
|
||||
$limit = (int) $input->get('limit');
|
||||
if(!$limit || $limit > 100) $limit = 100;
|
||||
$start = (int) $input->get('start');
|
||||
$options['items'] = $this->pages->find("start=$start, limit=$limit");
|
||||
if(empty($options['itemLabel'])) $options['itemLabel'] = $this->jsonListLabel;
|
||||
|
||||
foreach($options['items'] as $page) {
|
||||
if(!$page->editable()) $options['items']->remove($page);
|
||||
$label = $page->get($options['itemLabel']);
|
||||
$a = array();
|
||||
foreach(explode(' ', $page->statusStr) as $status) {
|
||||
if($status) $a[] = 'PageListStatus' . ucfirst($status);
|
||||
}
|
||||
$label = $sanitizer->entities1($label);
|
||||
if(count($a)) $label = "<span class='" . implode(' ', $a) . "'>$label</span>";
|
||||
$page->setQuietly('_itemLabel', $label);
|
||||
$options['entityEncode'] = false;
|
||||
}
|
||||
|
||||
$parent = $this->pages->getParent();
|
||||
if($parent && $parent->id && $parent->addable()) {
|
||||
$options['add'] = 'add/';
|
||||
} else {
|
||||
$options['add'] = false;
|
||||
}
|
||||
$options['edit'] = "edit/?id={id}";
|
||||
}
|
||||
|
||||
$options['itemLabel'] = '_itemLabel';
|
||||
|
||||
return parent::___executeNavJSON($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instanceof ProcessPageLister or null if not applicable
|
||||
|
Reference in New Issue
Block a user