From: Stephen Cameron Date: Fri, 4 Feb 2022 21:56:18 +0000 (+0100) Subject: CMS backend improvements. WIP #4893 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=fd8a1e4b6aafda2ed462b59cd5d11c8989bd2451;p=cubist_cms-back.git CMS backend improvements. WIP #4893 @1 --- diff --git a/src/app/Magic/Fields/CMSTemplate.php b/src/app/Magic/Fields/CMSTemplate.php index 244e480..98cf450 100644 --- a/src/app/Magic/Fields/CMSTemplate.php +++ b/src/app/Magic/Fields/CMSTemplate.php @@ -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); } } diff --git a/src/app/Magic/Fields/Model.php b/src/app/Magic/Fields/Model.php index feec9cb..3af8c40 100644 --- a/src/app/Magic/Fields/Model.php +++ b/src/app/Magic/Fields/Model.php @@ -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()