From c5f2eca96cd2efc20bcdf3a7773e4e9f37be6e46 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 19 Jun 2019 15:35:04 +0200 Subject: [PATCH] #2843 --- src/app/Magic/CubistMagicAttribute.php | 29 +++++++++++++ src/app/Magic/Fields/BunchOfFields.php | 18 ++++++++ src/app/Magic/Fields/Field.php | 2 +- src/app/PageManager/Models/Page.php | 12 ++++++ src/resources/views/fields/bunch.blade.php | 49 ++++++++++++++++++++++ 5 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/app/PageManager/Models/Page.php create mode 100644 src/resources/views/fields/bunch.blade.php diff --git a/src/app/Magic/CubistMagicAttribute.php b/src/app/Magic/CubistMagicAttribute.php index 004f8ec..70c70cd 100644 --- a/src/app/Magic/CubistMagicAttribute.php +++ b/src/app/Magic/CubistMagicAttribute.php @@ -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); + } } diff --git a/src/app/Magic/Fields/BunchOfFields.php b/src/app/Magic/Fields/BunchOfFields.php index b67b400..9c02d90 100644 --- a/src/app/Magic/Fields/BunchOfFields.php +++ b/src/app/Magic/Fields/BunchOfFields.php @@ -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()); } } diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index aa88d1c..c6cfc7f 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -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 index 0000000..840f4fb --- /dev/null +++ b/src/app/PageManager/Models/Page.php @@ -0,0 +1,12 @@ + + + + +
+ + @include('crud::inc.field_translatable_icon') +
+ + @include('crud::inc.show_fields', array('fields'=>$field['bunchfields'])) + +
+ + {{-- HINT --}} + @if (isset($field['hint'])) +

{!! $field['hint'] !!}

+ @endif + +
+ + +{{-- ########################################## --}} +{{-- 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') + + @endpush + + {{-- FIELD JS - will be loaded in the after_scripts section --}} + @push('crud_fields_scripts') + + @endpush + +@endif +{{-- End of Extra CSS and JS --}} +{{-- ########################################## --}} -- 2.39.5