From: Vincent Vanwaelscappel Date: Thu, 19 May 2022 17:48:20 +0000 (+0200) Subject: wip #4285 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=160c476138d0c3823219c632558a54065b93f31b;p=cubist_cms-back.git wip #4285 @1 --- diff --git a/src/app/Application.php b/src/app/Application.php index 3b5f7d5..27a0caa 100644 --- a/src/app/Application.php +++ b/src/app/Application.php @@ -2,8 +2,15 @@ namespace Cubist\Backpack; +use Backpack\CRUD\app\Library\CrudPanel\CrudPanel; + class Application extends \Illuminate\Foundation\Application { + /** + * @var CrudPanel + */ + protected $crud=null; + /** * @var string */ @@ -40,4 +47,21 @@ class Application extends \Illuminate\Foundation\Application { return $this->variant; } + + + /** + * @param CrudPanel $crud + */ + public function setCrud(?CrudPanel $crud): void + { + $this->crud = $crud; + } + + /** + * @return CrudPanel + */ + public function getCrud(): ?CrudPanel + { + return $this->crud; + } } diff --git a/src/app/Magic/BunchOfFields.php b/src/app/Magic/BunchOfFields.php index 617a015..038c37c 100644 --- a/src/app/Magic/BunchOfFields.php +++ b/src/app/Magic/BunchOfFields.php @@ -9,6 +9,11 @@ use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel; trait BunchOfFields { + /** + * @var InterfaceBunchOfFields + */ + protected $_rootEntry = null; + /** * @var Field[] */ @@ -30,6 +35,8 @@ trait BunchOfFields $attributes = CubistMagicAbstractModel::normalizeAttributes($name, $type, $label, $attributes); $attributes = array_merge($this->defaultFieldAttributes, $attributes); $field = Field::getInstance($attributes); + $field->setParentEntry($this); + $field->setRootEntry($this->getRootEntry()); $key = $field->getAttribute('name'); @@ -80,4 +87,20 @@ trait BunchOfFields { return isset($this->_fields[$name]); } + + /** + * @return InterfaceBunchOfFields + */ + public function getRootEntry(): ?InterfaceBunchOfFields + { + return (null !== $this->_rootEntry) ? $this->_rootEntry : $this; + } + + /** + * @param InterfaceBunchOfFields $rootEntry + */ + public function setRootEntry(InterfaceBunchOfFields $rootEntry): void + { + $this->_rootEntry = $rootEntry; + } } diff --git a/src/app/Magic/Fields/BunchOfFieldsMultiple.php b/src/app/Magic/Fields/BunchOfFieldsMultiple.php index 776538c..309e4e8 100644 --- a/src/app/Magic/Fields/BunchOfFieldsMultiple.php +++ b/src/app/Magic/Fields/BunchOfFieldsMultiple.php @@ -4,8 +4,9 @@ namespace Cubist\Backpack\Magic\Fields; use Cubist\Backpack\CubistBackpackServiceProvider; +use Cubist\Backpack\Magic\InterfaceBunchOfFields; -class BunchOfFieldsMultiple extends BunchOfFields +class BunchOfFieldsMultiple extends BunchOfFields implements InterfaceBunchOfFields { use \Cubist\Backpack\Magic\BunchOfFields; @@ -34,6 +35,7 @@ class BunchOfFieldsMultiple extends BunchOfFields protected function _setBunchOfFields() { + $bunch = $this->getAttribute('bunch'); if (is_array($bunch)) { foreach ($bunch as $item) { @@ -59,6 +61,8 @@ class BunchOfFieldsMultiple extends BunchOfFields $crudfields = []; foreach ($this->_fields as $field) { + $field->setParentEntry($this); + //$field->setRootEntry($this->getRootEntry()); $name = $field->getAttribute('name'); $e = explode('[', $name); $main = array_shift($e); diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index 689767d..1eeebce 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -6,6 +6,7 @@ namespace Cubist\Backpack\Magic\Fields; use Cubist\Backpack\CubistCrudPanel; use Cubist\Backpack\Magic\CubistMagicAttribute; use Cubist\Backpack\CubistBackpackServiceProvider; +use Cubist\Backpack\Magic\InterfaceBunchOfFields; use Doctrine\DBAL\Schema\Table; use Exception; use Illuminate\Support\Arr; @@ -19,6 +20,16 @@ class Field implements \ArrayAccess protected $_attributes; protected $_rules = []; + /** + * @var InterfaceBunchOfFields + */ + protected $_parentEntry = null; + + /** + * @var InterfaceBunchOfFields + */ + protected $_rootEntry = null; + protected $_isRelationship = false; protected $_columnType = 'text'; @@ -432,6 +443,38 @@ class Field implements \ArrayAccess return $value; } + /** + * @return InterfaceBunchOfFields + */ + public function getRootEntry(): ?InterfaceBunchOfFields + { + return $this->_rootEntry; + } + + /** + * @return InterfaceBunchOfFields + */ + public function getParentEntry(): ?InterfaceBunchOfFields + { + return $this->_parentEntry; + } + + /** + * @param InterfaceBunchOfFields $rootEntry + */ + public function setRootEntry(InterfaceBunchOfFields $rootEntry): void + { + $this->_rootEntry = $rootEntry; + } + + /** + * @param InterfaceBunchOfFields $parentEntry + */ + public function setParentEntry(InterfaceBunchOfFields $parentEntry): void + { + $this->_parentEntry = $parentEntry; + } + public function isRelationship() { return $this->_isRelationship; diff --git a/src/app/Magic/Form.php b/src/app/Magic/Form.php index 8ddf68b..51cee8a 100644 --- a/src/app/Magic/Form.php +++ b/src/app/Magic/Form.php @@ -6,7 +6,6 @@ namespace Cubist\Backpack\Magic; use Cubist\Backpack\CubistBackpackServiceProvider; use Cubist\Backpack\CubistCrudPanel; -use Cubist\Backpack\Magic\Fields\Field; use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel; class Form extends SubForm diff --git a/src/app/Magic/InterfaceBunchOfFields.php b/src/app/Magic/InterfaceBunchOfFields.php new file mode 100644 index 0000000..851f5b0 --- /dev/null +++ b/src/app/Magic/InterfaceBunchOfFields.php @@ -0,0 +1,40 @@ +