From 634c97aa0f65bb7fca82829cc9f952d63d83c5bc Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Mon, 2 May 2022 10:10:11 -0400 Subject: [PATCH] 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. --- .../InputfieldSelector/InputfieldSelector.module | 12 ++++++++---- .../ProcessPageLister/ProcessPageLister.module | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module b/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module index 42773f16..54c7b7d9 100644 --- a/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module +++ b/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module @@ -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 diff --git a/wire/modules/Process/ProcessPageLister/ProcessPageLister.module b/wire/modules/Process/ProcessPageLister/ProcessPageLister.module index 751877b5..5c462a6c 100644 --- a/wire/modules/Process/ProcessPageLister/ProcessPageLister.module +++ b/wire/modules/Process/ProcessPageLister/ProcessPageLister.module @@ -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 = '';