]> _ Git - cubist_cms-back.git/commitdiff
#2810
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Jun 2019 13:29:11 +0000 (15:29 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Jun 2019 13:29:11 +0000 (15:29 +0200)
src/app/Magic/Fields/Model.php
src/app/Magic/Fields/SelectFromModelMultiple.php

index f9c01da7f957894e422e1d924899268114bbbd09..e3602a995aad2b8a795fecc1755c1a9a942fffc1 100644 (file)
@@ -23,14 +23,8 @@ class Model extends Field
     protected function _getOptions()
     {
         $modelClass = $this->getAttribute('model');
-        /** @var CubistMagicAbstractModel[] $items */
-        $items = $modelClass::all();
-        $options = [];
+        $inst = new $modelClass();
 
-        $name = $this->getAttribute('attribute');
-        foreach ($items as $item) {
-            $options[$item->{$item->getPrimaryKey()}] = $item->{$name};
-        }
-        return $options;
+        return $modelClass::all()->pluck($this->getAttribute('attribute'), $inst->getPrimaryKey());
     }
 }
index 378f606b71289f73200c7bc7a45a6255b7e78d05..7461e40eb9dc3b3e337288500dcaa7d7830f4b00 100644 (file)
@@ -8,4 +8,18 @@ class SelectFromModelMultiple extends SelectFromModel
 {
     protected $_multiple = true;
     protected $_cast = 'array';
+    protected $_order = false;
+
+    public function _postSetAttributes()
+    {
+        parent::_postSetAttributes(); // TODO: Change the autogenerated stub
+        if ($this->getAttribute('order')) {
+            $this->_adminType = 'select_and_order';
+        }
+    }
+
+    public function getDefaultAttributes()
+    {
+        return array_merge(parent::getDefaultAttributes(), ['order' => $this->_order]);
+    }
 }