namespace Cubist\Backpack;
+use Backpack\CRUD\app\Library\CrudPanel\CrudPanel;
+
class Application extends \Illuminate\Foundation\Application
{
+ /**
+ * @var CrudPanel
+ */
+ protected $crud=null;
+
/**
* @var string
*/
{
return $this->variant;
}
+
+
+ /**
+ * @param CrudPanel $crud
+ */
+ public function setCrud(?CrudPanel $crud): void
+ {
+ $this->crud = $crud;
+ }
+
+ /**
+ * @return CrudPanel
+ */
+ public function getCrud(): ?CrudPanel
+ {
+ return $this->crud;
+ }
}
trait BunchOfFields
{
+ /**
+ * @var InterfaceBunchOfFields
+ */
+ protected $_rootEntry = null;
+
/**
* @var Field[]
*/
$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');
{
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;
+ }
}
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;
protected function _setBunchOfFields()
{
+
$bunch = $this->getAttribute('bunch');
if (is_array($bunch)) {
foreach ($bunch as $item) {
$crudfields = [];
foreach ($this->_fields as $field) {
+ $field->setParentEntry($this);
+ //$field->setRootEntry($this->getRootEntry());
$name = $field->getAttribute('name');
$e = explode('[', $name);
$main = array_shift($e);
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;
protected $_attributes;
protected $_rules = [];
+ /**
+ * @var InterfaceBunchOfFields
+ */
+ protected $_parentEntry = null;
+
+ /**
+ * @var InterfaceBunchOfFields
+ */
+ protected $_rootEntry = null;
+
protected $_isRelationship = false;
protected $_columnType = 'text';
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;
use Cubist\Backpack\CubistBackpackServiceProvider;
use Cubist\Backpack\CubistCrudPanel;
-use Cubist\Backpack\Magic\Fields\Field;
use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
class Form extends SubForm
--- /dev/null
+<?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;
+}
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;
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;
namespace Cubist\Backpack\Magic;
-class SubForm
+class SubForm implements InterfaceBunchOfFields
{
use BunchOfFields;