From: Vincent Vanwaelscappel Date: Thu, 7 Jan 2021 16:39:27 +0000 (+0100) Subject: wip #4174 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=11753440231870534189111269b8abeb19325807;p=cubist_cms-back.git wip #4174 @1 --- diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index 65ed88b..8102c79 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -28,6 +28,9 @@ class Field implements \ArrayAccess protected $_filterType = 'simple'; protected $_filterValues = null; + protected $_prefix = null; + protected $_suffix = null; + protected $_adminType = 'text'; protected $_viewNamespace = 'crud::fields'; protected $_columnViewNamespace = 'crud::columns'; @@ -117,7 +120,9 @@ class Field implements \ArrayAccess public function getDefaultAttributes() { - return ['type' => $this->_adminType, 'view_namespace' => $this->_viewNamespace, 'column' => false, 'form' => 'both', 'rules' => '', + return [ + 'type' => $this->_adminType, 'view_namespace' => $this->_viewNamespace, 'column' => false, 'form' => 'both', 'rules' => '', + 'prefix' => $this->_prefix, 'suffix' => $this->_suffix, 'fillable' => true, 'guarded' => false, 'hidden' => false, 'filter' => false, 'filter_type' => $this->_filterType, 'filter_label' => null, 'filter_values' => $this->_filterValues, 'translatable' => $this->_translatable, 'migrateTranslatable' => $this->_migrateTranslatable, diff --git a/src/app/Magic/Fields/FolderTree.php b/src/app/Magic/Fields/FolderTree.php deleted file mode 100644 index 12a1968..0000000 --- a/src/app/Magic/Fields/FolderTree.php +++ /dev/null @@ -1,45 +0,0 @@ -_root = $root; - } - - /** - * @return string - */ - public function getRoot(): string - { - return $this->_root; - } - - /** - * @return array - */ - public function getOptions(): array - { - $options = []; - - $iterator = \Cubist\Util\Files\Files::getRecursiveDirectoryIterator($this->getRoot()); - - foreach ($iterator as $item) { - /** @var $item \SplFileInfo */ - if ($item->isFile()) { - continue; - } - $options[$item->getFilename()] = $item->getFilename(); - } - return $options; - } -} diff --git a/src/app/Magic/Fields/SelectFromArray.php b/src/app/Magic/Fields/SelectFromArray.php index 1f8e0bd..8f68334 100644 --- a/src/app/Magic/Fields/SelectFromArray.php +++ b/src/app/Magic/Fields/SelectFromArray.php @@ -21,7 +21,12 @@ class SelectFromArray extends Field public function getDefaultAttributes() { - return array_merge(parent::getDefaultAttributes(), ['options' => $this->_options, 'options_aliases' => $this->_options_aliases, 'allows_null' => $this->_allowNull, 'allows_multiple' => $this->_multiple]); + return array_merge(parent::getDefaultAttributes(), ['options' => $this->getOptions(), 'options_aliases' => $this->_options_aliases, 'allows_null' => $this->_allowNull, 'allows_multiple' => $this->_multiple]); + } + + public function getOptions() + { + return $this->_options; } public function getColumnData() diff --git a/src/app/Magic/Form.php b/src/app/Magic/Form.php index 1588b7d..de3b712 100644 --- a/src/app/Magic/Form.php +++ b/src/app/Magic/Form.php @@ -5,7 +5,9 @@ namespace Cubist\Backpack\Magic; use Cubist\Backpack\CubistBackpackServiceProvider; -use Illuminate\Support\Facades\Http; +use Cubist\Backpack\CubistCrudPanel; +use Cubist\Backpack\Magic\Fields\Field; +use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel; class Form extends SubForm { @@ -14,13 +16,16 @@ class Form extends SubForm protected $_enctype = 'application/x-www-form-urlencoded'; protected $_csrf = true; protected $_title = ''; - + protected $crud; public function __construct($action = '', $method = 'post') { $this->setAction($action); $this->setMethod($method); + $this->crud = new CubistCrudPanel(); + $this->crud->model=new CubistMagicAbstractModel(); parent::__construct(); + } /** @@ -29,7 +34,7 @@ class Form extends SubForm public function render(callable $callback = null) { - return view(CubistBackpackServiceProvider::NAMESPACE . '::form.form', ['form' => $this])->render($callback); + return view(CubistBackpackServiceProvider::NAMESPACE . '::form.form', ['form' => $this, 'crud' => $this->crud])->render($callback); } public function __toString() @@ -127,16 +132,21 @@ class Form extends SubForm return []; } - public function fields() + public function addField($name, $type = 'Text', $label = '', $attributes = []) { - return []; + $field = parent::addField($name, $type, $label, $attributes); + $this->crud->addField($field->getDefinition()); + + return $field; } - public function getAutoFocusOnFirstField(){ + public function getAutoFocusOnFirstField() + { return true; } - public function inlineErrorsEnabled(){ + public function inlineErrorsEnabled() + { return false; } } diff --git a/src/resources/views/form/form.blade.php b/src/resources/views/form/form.blade.php index 4fa79ed..9649ef8 100644 --- a/src/resources/views/form/form.blade.php +++ b/src/resources/views/form/form.blade.php @@ -1,7 +1,6 @@ @php - $crud=$form; $action='create'; - $fields=$form->fields(); + $fields=$crud->fields(); @endphp

{{$form->getTitle()}}