From d6aeead6a01b95233db903cc1c4d6e4181f5b184 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 26 Nov 2020 18:34:16 +0100 Subject: [PATCH] wip #3753 @4 --- src/app/CubistCrudPanel.php | 14 ++++++++++++++ src/app/Magic/Fields/Model.php | 2 +- src/app/Magic/Fields/ModelAttribute.php | 6 +++++- src/app/Magic/Fields/SelectFromModel.php | 12 +++++++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/app/CubistCrudPanel.php b/src/app/CubistCrudPanel.php index bf100db..03d5f8f 100644 --- a/src/app/CubistCrudPanel.php +++ b/src/app/CubistCrudPanel.php @@ -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']; diff --git a/src/app/Magic/Fields/Model.php b/src/app/Magic/Fields/Model.php index ea9b3ed..958a5bd 100644 --- a/src/app/Magic/Fields/Model.php +++ b/src/app/Magic/Fields/Model.php @@ -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() diff --git a/src/app/Magic/Fields/ModelAttribute.php b/src/app/Magic/Fields/ModelAttribute.php index dc35e8c..34d5a78 100644 --- a/src/app/Magic/Fields/ModelAttribute.php +++ b/src/app/Magic/Fields/ModelAttribute.php @@ -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 '-'; } } } diff --git a/src/app/Magic/Fields/SelectFromModel.php b/src/app/Magic/Fields/SelectFromModel.php index e42a8aa..1686a81 100644 --- a/src/app/Magic/Fields/SelectFromModel.php +++ b/src/app/Magic/Fields/SelectFromModel.php @@ -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')); + } } -- 2.39.5