]> _ Git - cubist_cms-back.git/commitdiff
wip #3753 @4
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 26 Nov 2020 17:34:16 +0000 (18:34 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 26 Nov 2020 17:34:16 +0000 (18:34 +0100)
src/app/CubistCrudPanel.php
src/app/Magic/Fields/Model.php
src/app/Magic/Fields/ModelAttribute.php
src/app/Magic/Fields/SelectFromModel.php

index bf100db98afd50fc244c175505acd62dac8f3a98..03d5f8f4636a0beb7aca291308fc9345b03403bd 100644 (file)
@@ -15,6 +15,7 @@ use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
 class CubistCrudPanel extends CrudPanel
 {
     protected $_seenFieldTypes = [];
+    protected $_values = [];
 
     public function hasField($name)
     {
@@ -36,6 +37,19 @@ class CubistCrudPanel extends CrudPanel
         return $this->getEntry($this->getCurrentEntryId());
     }
 
+    public function getValue($key, $default = null)
+    {
+        if (isset($this->_values[$key])) {
+            return $this->_values[$key];
+        }
+        return $default;
+    }
+
+    public function setValue($key, $value)
+    {
+        $this->_values[$key] = $value;
+    }
+
     public function checkIfFieldIsFirstOfItsType($field)
     {
         $type = $field['type'];
index ea9b3edc50d6524c926e846c7f1c81ad2e4bcba4..958a5bd98bc94989dc599500099473ca3bd64568 100644 (file)
@@ -10,7 +10,7 @@ class Model extends Field
 
     public function getDefaultAttributes()
     {
-        return array_merge(parent::getDefaultAttributes(), ['attribute' => 'name', 'allows_null' => false, 'allows_multiple' => $this->_multiple]);
+        return array_merge(parent::getDefaultAttributes(), ['attribute' => 'name', 'column_attribute' => null, 'allows_null' => false, 'allows_multiple' => $this->_multiple]);
     }
 
     protected function _getOptions()
index dc35e8cdc4677a475d957c86f95ed06141181ef8..34d5a7810dbc30d031b14922aac8928960eace6d 100644 (file)
@@ -22,7 +22,11 @@ class ModelAttribute extends StaticValue
         if ($i instanceof CubistMagicAbstractModel) {
             $f = $i->getField($e[0]);
             if ($f instanceof Model) {
-                return $f->pluck($e[1])[$v0];
+                $a = $f->pluck($e[1]);
+                if (isset($a[$v0])) {
+                    return $a[$v0];
+                }
+                return '-';
             }
         }
     }
index e42a8aa835074781a0e91d67d9e47a2003cffc18..1686a81f9fbfd68a35718711648cd485cee32a2f 100644 (file)
@@ -53,7 +53,17 @@ class SelectFromModel extends Model
     public function getColumnData()
     {
         $res = parent::getColumnData();
-        $res['options'] = $this->_getOptions();
+        $res['options'] = $this->_getColumnOptions();
         return $res;
     }
+
+    protected function _getColumnOptions()
+    {
+        $ca = $this->getAttribute('column_attribute');
+        if (null === $ca || $this->getAttribute('attribute') === $ca) {
+            return $this->_getOptions();
+        }
+
+        return $this->pluck($this->getAttribute('column_attribute'));
+    }
 }