]> _ Git - cubist_cms-back.git/commitdiff
wip #4174 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 7 Jan 2021 16:39:27 +0000 (17:39 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 7 Jan 2021 16:39:27 +0000 (17:39 +0100)
src/app/Magic/Fields/Field.php
src/app/Magic/Fields/FolderTree.php [deleted file]
src/app/Magic/Fields/SelectFromArray.php
src/app/Magic/Form.php
src/resources/views/form/form.blade.php

index 65ed88b41fc9f14686346b99d235b0a1329ea3ad..8102c795880ac5f714d79758d3e264d6a0ddefbf 100644 (file)
@@ -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 (file)
index 12a1968..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-
-
-namespace Cubist\Backpack\Magic\Fields;
-
-
-class FolderTree extends SelectFromArray
-{
-    protected $_root = '';
-
-    /**
-     * @param string $root
-     */
-    public function setRoot(string $root): void
-    {
-        $this->_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;
-    }
-}
index 1f8e0bdb7c662b18a02df7f6eae7022879c716ed..8f683342e98a529942cc7af185978b3e963a5bdf 100644 (file)
@@ -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()
index 1588b7dffa9eeee4bbd34485ee0a117b302bf7ea..de3b7125407a8649299f2a34c5b1401391f25084 100644 (file)
@@ -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;
     }
 }
index 4fa79ed7dc75b06911d8462ed87f6c9c8b49e46a..9649ef8583c993a9f596bd9186b151629f39379f 100644 (file)
@@ -1,7 +1,6 @@
 @php
-    $crud=$form;
     $action='create';
-    $fields=$form->fields();
+    $fields=$crud->fields();
 @endphp
 
 <h2>{{$form->getTitle()}}</h2>