From 1af408a4e230f553ddbca472d138011954f32a87 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 20 Jan 2021 17:38:22 +0100 Subject: [PATCH] wip #4216 @1 --- .../Console/Commands/CubistMagicCommand.php | 2 +- src/app/Magic/Fields/Color.php | 7 +++++ src/app/Magic/Fields/Field.php | 7 +++-- src/app/Magic/Fields/FormSeparator.php | 13 +++++++++ src/app/Magic/Fields/UnstoredField.php | 10 +++++++ .../Magic/Models/CubistMagicAbstractModel.php | 4 +++ src/resources/views/fields/color.blade.php | 28 +++++++++---------- 7 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 src/app/Magic/Fields/FormSeparator.php create mode 100644 src/app/Magic/Fields/UnstoredField.php diff --git a/src/app/Console/Commands/CubistMagicCommand.php b/src/app/Console/Commands/CubistMagicCommand.php index bf18824..a76d696 100644 --- a/src/app/Console/Commands/CubistMagicCommand.php +++ b/src/app/Console/Commands/CubistMagicCommand.php @@ -29,7 +29,7 @@ class CubistMagicCommand extends CubistCommand } } } catch (\Exception $e) { - $this->line($e->getMessage()); + $this->line($e->getTraceAsString()); } } } diff --git a/src/app/Magic/Fields/Color.php b/src/app/Magic/Fields/Color.php index d050979..d2a7a9f 100644 --- a/src/app/Magic/Fields/Color.php +++ b/src/app/Magic/Fields/Color.php @@ -10,4 +10,11 @@ class Color extends Field { protected $_adminType = 'color'; protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields'; + + protected $_allowsAlpha = true; + + public function getDefaultAttributes() + { + return array_merge(parent::getDefaultAttributes(), ['allows_alpha' => $this->_allowsAlpha]); + } } diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index 8102c79..5c68568 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -70,11 +70,12 @@ class Field implements \ArrayAccess if (!isset($attributes['type'])) { throw new Exception('You must specify a field type'); } - if (!isset($attributes['name'])) { - throw new Exception('You must specify a field name'); - } + $class = static::_getClass($attributes['type']); unset($attributes['type']); + if (!is_subclass_of($class, UnstoredField::class) && !isset($attributes['name'])) { + throw new Exception('You must specify a field name'); + } return new $class($attributes); } diff --git a/src/app/Magic/Fields/FormSeparator.php b/src/app/Magic/Fields/FormSeparator.php new file mode 100644 index 0000000..393ac06 --- /dev/null +++ b/src/app/Magic/Fields/FormSeparator.php @@ -0,0 +1,13 @@ +setPrimaryKey([$this->primaryKey], 'pk_' . $this->table); foreach ($this->_fields as $field) { + if ($field instanceof UnstoredField) { + continue; + } if ($field->getAttribute('fake', false) !== false) { continue; } diff --git a/src/resources/views/fields/color.blade.php b/src/resources/views/fields/color.blade.php index 615e152..23cc049 100644 --- a/src/resources/views/fields/color.blade.php +++ b/src/resources/views/fields/color.blade.php @@ -1,19 +1,20 @@ @include('crud::fields.inc.wrapper_start') - - @include('crud::fields.inc.translatable_icon') - + +@include('crud::fields.inc.translatable_icon') + - {{-- HINT --}} - @if (isset($field['hint'])) -

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

- @endif +{{-- HINT --}} +@if (isset($field['hint'])) +

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

+@endif @include('crud::fields.inc.wrapper_end') {{-- ########################################## --}} @@ -33,7 +34,6 @@