]> _ Git - cubist_cms-back.git/commitdiff
CMS backend improvements. WIP #4893 @1
authorStephen Cameron <stephen@cubedesigners.com>
Fri, 4 Feb 2022 21:56:18 +0000 (22:56 +0100)
committerStephen Cameron <stephen@cubedesigners.com>
Fri, 4 Feb 2022 21:56:18 +0000 (22:56 +0100)
src/app/Magic/Fields/CMSTemplate.php
src/app/Magic/Fields/Model.php

index 244e4806acd3238a67373c2020669e2ba33f1b86..98cf450df9f191623b23c470452bb0f6f28bc627 100644 (file)
@@ -22,6 +22,9 @@ class CMSTemplate extends SelectFromArray
         foreach ($templates as $name => $template) {
             $options[Str::snake($name)] = $template->getName();
         }
+
+        asort($options); // Alphabetically sort templates by their display names
+
         $this->setAttribute('options', $options);
     }
 }
index feec9cb75c1d9d39dabbd812cb017776f9487e05..3af8c40e741bc900e8bba2b526affeb2f2e54b4f 100644 (file)
@@ -29,7 +29,10 @@ class Model extends Field
         $inst = new $modelClass();
 
         $attr=$this->getAttribute('attribute');
-        return $modelClass::orderBy($attr)->get()->pluck($attr, $inst->getPrimaryKey())->toArray();
+        // Allow the attribute to be a custom accessor.
+        // For this to work, the query is done first, then the Collection object handles it
+        // Ref: https://stackoverflow.com/a/44475575
+        return $modelClass::get()->sortBy($attr)->pluck($attr, $inst->getPrimaryKey())->toArray();
     }
 
     public function getDatabaseType()