]> _ Git - cubist_cms-back.git/commitdiff
#2843
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 Jun 2019 13:35:04 +0000 (15:35 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 Jun 2019 13:35:04 +0000 (15:35 +0200)
src/app/Magic/CubistMagicAttribute.php
src/app/Magic/Fields/BunchOfFields.php
src/app/Magic/Fields/Field.php
src/app/PageManager/Models/Page.php [new file with mode: 0644]
src/resources/views/fields/bunch.blade.php [new file with mode: 0644]

index 004f8ece2a1e3dab74cbbcd8c6986685675b7dfe..70c70cd2465d31079ea2648ea76311a1c1f0afff 100644 (file)
@@ -14,6 +14,11 @@ trait CubistMagicAttribute
         return Arr::get($this->_attributes, $key, $default);
     }
 
+    public function unsetAttribute($key)
+    {
+        $this->setAttribute($key, null);
+    }
+
     public function hasAttribute($key)
     {
         $key = $this->_attribute($key);
@@ -51,4 +56,28 @@ trait CubistMagicAttribute
     {
         return [];
     }
+
+    public function offsetSet($offset, $value)
+    {
+        if (is_null($offset)) {
+
+        } else {
+            $this->setAttribute($offset, $value);
+        }
+    }
+
+    public function offsetExists($offset)
+    {
+        return $this->hasAttribute($offset);
+    }
+
+    public function offsetUnset($offset)
+    {
+        $this->unsetAttribute($offset);
+    }
+
+    public function offsetGet($offset)
+    {
+        return $this->getAttribute($offset, null);
+    }
 }
index b67b4005887d7748869728bf30d3f1eeda6b126d..9c02d90317a88bee197050fef139089804be3bc3 100644 (file)
@@ -3,10 +3,16 @@
 
 namespace Cubist\Backpack\app\Magic\Fields;
 
+use Cubist\Backpack\CubistBackpackServiceProvider;
+
 class BunchOfFields extends Field
 {
     use \Cubist\Backpack\app\Magic\BunchOfFields;
 
+    protected $_adminType = 'bunch';
+    protected $_cast = 'array';
+    protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+
     public function getDefaultAttributes()
     {
         return array_merge(parent::getDefaultAttributes(), ['bunch' => []]);
@@ -39,5 +45,17 @@ class BunchOfFields extends Field
                 }
             }
         }
+
+        foreach ($this->_fields as $field) {
+            $name = $field->getAttribute('name');
+            $e = explode('[', $name);
+            $main = array_shift($e);
+            $name = $this->getAttribute('name') . '[' . $main . ']';
+            foreach ($e as $item) {
+                $name .= '[' . $item . ']';
+            }
+            $field->setAttribute('name', $name);
+        }
+        $this->setAttribute('bunchfields', $this->getFields());
     }
 }
index aa88d1cb13b47edf2555c7ee528350e37d28d10f..c6cfc7f03c6912e77d6abb3300dada1973b784c3 100644 (file)
@@ -9,7 +9,7 @@ use Exception;
 use Illuminate\Support\Str;
 use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
 
-class Field
+class Field implements \ArrayAccess
 {
     use CubistMagicAttribute;
     protected $_attributes;
diff --git a/src/app/PageManager/Models/Page.php b/src/app/PageManager/Models/Page.php
new file mode 100644 (file)
index 0000000..840f4fb
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+
+namespace app\PageManager\Models;
+
+
+use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
+
+class Page extends \Backpack\PageManager\app\Models\Page
+{
+    use HasMediaTrait;
+}
diff --git a/src/resources/views/fields/bunch.blade.php b/src/resources/views/fields/bunch.blade.php
new file mode 100644 (file)
index 0000000..c5f9593
--- /dev/null
@@ -0,0 +1,49 @@
+<!-- Bunch -->
+
+<?php
+
+
+?>
+
+<div @include('crud::inc.field_wrapper_attributes') >
+    <label>{!! $field['label'] !!}</label>
+    @include('crud::inc.field_translatable_icon')
+    <div class="clearfix"></div>
+
+    @include('crud::inc.show_fields', array('fields'=>$field['bunchfields']))
+
+    <div class="clearfix"></div>
+
+    {{-- HINT --}}
+    @if (isset($field['hint']))
+        <p class="help-block">{!! $field['hint'] !!}</p>
+    @endif
+
+</div>
+
+
+{{-- ########################################## --}}
+{{-- Extra CSS and JS for this particular field --}}
+{{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}}
+@if ($crud->checkIfFieldIsFirstOfItsType($field))
+
+    {{-- FIELD CSS - will be loaded in the after_styles section --}}
+    @push('crud_fields_styles')
+        <style type="text/css">
+
+        </style>
+    @endpush
+
+    {{-- FIELD JS - will be loaded in the after_scripts section --}}
+    @push('crud_fields_scripts')
+        <script>
+            jQuery(document).ready(function ($) {
+
+
+            });
+        </script>
+    @endpush
+
+@endif
+{{-- End of Extra CSS and JS --}}
+{{-- ########################################## --}}