diff --git a/wire/core/Process.php b/wire/core/Process.php
index 72b5336b..28c8ff05 100644
--- a/wire/core/Process.php
+++ b/wire/core/Process.php
@@ -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 .= " $label2";
}
}
+ 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 = "$label";
+ }
+ }
+
$data['list'][$_label] = array(
'url' => str_replace(array('{id}', '{name}'), array($id, $name), $options['edit']),
'label' => $label,
diff --git a/wire/modules/Process/ProcessPageType/ProcessPageType.module b/wire/modules/Process/ProcessPageType/ProcessPageType.module
index 1a93af4c..f2f33fdc 100644
--- a/wire/modules/Process/ProcessPageType/ProcessPageType.module
+++ b/wire/modules/Process/ProcessPageType/ProcessPageType.module
@@ -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 = "$label";
+ $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