From 9fe7e95840d78d801f80829b51dba079287688ca Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 9 Feb 2024 10:40:50 -0500 Subject: [PATCH] Add processwire/processwire-requests#466 which fixes template order in InputfieldSelector. While there, I also updated it to correct field and option order in a couple other spots. --- .../InputfieldSelector.module | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module b/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module index 2f20a38d..2a0cb35c 100644 --- a/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module +++ b/wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module @@ -7,7 +7,7 @@ * Code by Ryan Cramer * Sponsored by Avoine * - * ProcessWire 3.x, Copyright 2023 by Ryan Cramer + * ProcessWire 3.x, Copyright 2024 by Ryan Cramer * https://processwire.com * * @todo add support for "custom: OR-group" option (https://processwire.com/talk/topic/13116-or-selecters-for-different-fields/) @@ -427,6 +427,7 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule { $templatesByLabel[$label] = $template; $templates[$template->id] = $label; } + asort($templates, SORT_NATURAL | SORT_FLAG_CASE); unset($templatesByLabel); // make users selectable if there are under $maxUsers of them @@ -718,7 +719,7 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule { while(isset($subfields[$key])) $key .= " "; $subfields[$key] = $subfield; } - ksort($subfields); + ksort($subfields, SORT_NATURAL | SORT_FLAG_CASE); if($this->showFieldLabels) { // convert back to name-based keys $_subfields = array(); @@ -926,20 +927,22 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule { $outSections[$optgroupName] = $out; unset($out); } + + $customFields = array(); - if($settings['showFieldLabels']) { - $customFields = array(); - foreach($settings['customFields'] as $field) { - /** @var Field $field */ + foreach($settings['customFields'] as $field) { + /** @var Field $field */ + if($settings['showFieldLabels']) { $label = $field->getLabel(); while(isset($customFields[$label])) $label .= ' '; - $customFields[$label] = $field; + } else { + $label = $field->name; } - ksort($customFields); - } else { - $customFields = $settings['customFields']; + $customFields[$label] = $field; } - + + ksort($customFields, SORT_NATURAL | SORT_FLAG_CASE); + $templates = $this->wire()->templates; // build custom fields optgroup @@ -1226,7 +1229,7 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule { $info['options'][$p->id] = $p->get('path'); } } - asort($info['options']); + asort($info['options'], SORT_NATURAL | SORT_FLAG_CASE); if(empty($info['options'])) unset($info['options']); } $type = $info['input'];