1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-20 05:21:29 +02:00

Update Lister and InputfieldSelector option to display Template labels (vs Template names) have additional logic as to when they display both, and be consistent with one another. They now take into account the Lister "useColumnLabels" setting as well.

This commit is contained in:
Ryan Cramer
2022-05-02 10:10:11 -04:00
parent 5651742660
commit 634c97aa0f
2 changed files with 17 additions and 4 deletions

View File

@@ -359,6 +359,7 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
$notLabel = $this->_('Not: %s');
$findOperators = array();
$findNotOperators = array();
$showFieldLabels = $this->showFieldLabels;
$operators = Selectors::getOperators(array(
'getIndexType' => 'operator',
@@ -407,16 +408,19 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
$this->operatorTrimChars = '.@';
$templates = array();
$templatesByLabel = array();
$initTemplates = $this->getTemplatesFromInitValue($this->initValue);
foreach($this->wire()->templates as $template) {
if(($template->flags & Template::flagSystem) && !$this->allowSystemTemplates) {
continue;
}
if(($template->flags & Template::flagSystem) && !$this->allowSystemTemplates) continue;
if(count($initTemplates) && !in_array($template->id, $initTemplates)) continue;
$label = $template->getLabel();
if($label != $template->name) $label .= " ($template->name)";
if(!$showFieldLabels || $showFieldLabels > 1 || isset($templatesByLabel[$label])) {
if(strtolower($template->name) != strtolower($label)) $label .= " ($template->name)";
}
$templatesByLabel[$label] = $template;
$templates[$template->id] = $label;
}
unset($templatesByLabel);
// make users selectable if there are under $maxUsers of them
// otherwise utilize the user ID property

View File

@@ -1573,6 +1573,15 @@ class ProcessPageLister extends Process implements ConfigurableModule {
$value = array();
foreach($this->statusLabels as $status => $label) if($p->hasStatus($status)) $value[] = $label;
$value = implode(', ', $value);
} else if($name === 'template') {
// template label or name
$allowName = $this->useColumnLabels ? trim($this->get('sort'), '-') === 'template' : true;
$t = $p->template;
$value = $t->getLabel();
// include template name only if it differs from template label
if($allowName && strtolower($t->name) != strtolower($value)) $value .= " ($t->name)";
if(!$noEntities) $value = $sanitizer->entities1($value);
} else if($field && $field->type) {
if($subname == 'data') $subname = '';