]> _ Git - cubist_cms-back.git/commitdiff
wip #4285 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 May 2022 17:48:20 +0000 (19:48 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 May 2022 17:48:20 +0000 (19:48 +0200)
src/app/Application.php
src/app/Magic/BunchOfFields.php
src/app/Magic/Fields/BunchOfFieldsMultiple.php
src/app/Magic/Fields/Field.php
src/app/Magic/Form.php
src/app/Magic/InterfaceBunchOfFields.php [new file with mode: 0644]
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Magic/SubForm.php

index 3b5f7d5849af09597564c117d7d8b24e20bfbb4c..27a0caa12b3e79aeb56e90cb06ddd844eee18fb2 100644 (file)
@@ -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;
+    }
 }
index 617a015255e4c56d06b147d7d93073aca6fc6e14..038c37c02a81dcc896638d4ae27180a2e973df6b 100644 (file)
@@ -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;
+    }
 }
index 776538cf59ae5e6da7b90c5e373c8adfc1f8921e..309e4e81ee1affc6b5266cfbcaf31cf379e88df6 100644 (file)
@@ -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);
index 689767dfe536feb59645950f162f97d0ce64877e..1eeebcef30c109f62dc4025d733462de56759bfe 100644 (file)
@@ -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;
index 8ddf68bc519e34158a803c5351e3f4a836b6bfce..51cee8a7392955901c26e17e1341286b47879e98 100644 (file)
@@ -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 (file)
index 0000000..851f5b0
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+namespace Cubist\Backpack\Magic;
+
+use Cubist\Backpack\Magic\Fields\Field;
+
+interface InterfaceBunchOfFields
+{
+
+    /**
+     * @param $attributes
+     * @return Field
+     * @throws \Exception
+     */
+    public function addField($name, $type = 'Text', $label = '', $attributes = []);
+
+    /**
+     * @param array $attributes
+     * @return Field
+     * @throws \Exception
+     */
+    public function addFakeField(array $attributes);
+
+    /**
+     * @return Field[]
+     */
+    public function getFields();
+
+    /**
+     * @param $name
+     * @return Field|null
+     */
+    public function getField($name);
+
+    /**
+     * @param $name string
+     * @return bool
+     */
+    public function hasField($name): bool;
+}
index be2b1be2672234c21128f6511b5ef01fc8b265f1..0d5db796d6c4d7bce7d8a199db3b71bfa470f2fe 100644 (file)
@@ -9,6 +9,7 @@ use Cubist\Backpack\Magic\Fields\Composed;
 use Cubist\Backpack\Magic\Fields\Datetime;
 use Cubist\Backpack\Magic\Fields\Files;
 use Cubist\Backpack\Magic\Fields\FilesOrURL;
+use Cubist\Backpack\Magic\InterfaceBunchOfFields;
 use Cubist\Backpack\Magic\Operations\CreateOperation;
 use Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
 use Cubist\Backpack\Magic\Operations\UpdateOperation;
@@ -41,7 +42,7 @@ use Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection;
 use Spatie\MediaLibrary\MediaCollections\Models\Media;
 use Venturecraft\Revisionable\RevisionableTrait;
 
-class CubistMagicAbstractModel extends Model implements HasMedia
+class CubistMagicAbstractModel extends Model implements HasMedia, InterfaceBunchOfFields
 {
     use CrudTrait;
     use InteractsWithMedia;
index 4a6560ff38e6bfc7ceeb13f82009a53727f3d961..1ebb0703cb8f89ebe8664b528febb8db845d518e 100644 (file)
@@ -4,7 +4,7 @@
 namespace Cubist\Backpack\Magic;
 
 
-class SubForm
+class SubForm implements InterfaceBunchOfFields
 {
     use BunchOfFields;