]> _ Git - cubist_cms-back.git/commitdiff
wip #4216 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 20 Jan 2021 16:38:22 +0000 (17:38 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 20 Jan 2021 16:38:22 +0000 (17:38 +0100)
src/app/Console/Commands/CubistMagicCommand.php
src/app/Magic/Fields/Color.php
src/app/Magic/Fields/Field.php
src/app/Magic/Fields/FormSeparator.php [new file with mode: 0644]
src/app/Magic/Fields/UnstoredField.php [new file with mode: 0644]
src/app/Magic/Models/CubistMagicAbstractModel.php
src/resources/views/fields/color.blade.php

index bf188246e6241f1b94f4da2ef3b6a48c4039ec86..a76d6963af6f382f95879feb58f30f19a6d4fc06 100644 (file)
@@ -29,7 +29,7 @@ class CubistMagicCommand extends CubistCommand
                         }
                     }
                 } catch (\Exception $e) {
-                    $this->line($e->getMessage());
+                    $this->line($e->getTraceAsString());
                 }
             }
         }
index d0509797328b9fb051d0013a23e0496db7f473c7..d2a7a9fdf3939af16917e641373e2fceace37c72 100644 (file)
@@ -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]);
+    }
 }
index 8102c795880ac5f714d79758d3e264d6a0ddefbf..5c685682492050e65eeb384c37b5f198de173277 100644 (file)
@@ -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 (file)
index 0000000..393ac06
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+
+namespace Cubist\Backpack\Magic\Fields;
+
+
+use Cubist\Backpack\CubistBackpackServiceProvider;
+
+class FormSeparator extends UnstoredField
+{
+    protected $_adminType = 'form_separator';
+    protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+}
diff --git a/src/app/Magic/Fields/UnstoredField.php b/src/app/Magic/Fields/UnstoredField.php
new file mode 100644 (file)
index 0000000..e96ee0a
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+
+
+namespace Cubist\Backpack\Magic\Fields;
+
+
+class UnstoredField extends Field
+{
+
+}
index be8310ba09010e52816dd712f19eab7cd0142631..45de7bad0b5f3066c534aeeef25ab6f0132489cb 100644 (file)
@@ -16,6 +16,7 @@ use Cubist\Backpack\Magic\BunchOfFields;
 use Cubist\Backpack\Magic\Controllers\CubistMagicController;
 use Cubist\Backpack\Magic\EntityData;
 use Cubist\Backpack\Magic\Fields\Field;
+use Cubist\Backpack\Magic\Fields\UnstoredField;
 use Cubist\Backpack\Magic\PageData;
 use Cubist\Backpack\Magic\QueryBuilder;
 use Cubist\Backpack\Magic\Requests\CubistMagicUpdateRequest;
@@ -440,6 +441,9 @@ class CubistMagicAbstractModel extends Model implements HasMedia
 
         $table->setPrimaryKey([$this->primaryKey], 'pk_' . $this->table);
         foreach ($this->_fields as $field) {
+            if ($field instanceof UnstoredField) {
+                continue;
+            }
             if ($field->getAttribute('fake', false) !== false) {
                 continue;
             }
index 615e15208d9459562d50024e391fab125283e069..23cc04914d6241a2c7ad49a2c98a75bbe059d32f 100644 (file)
@@ -1,19 +1,20 @@
 <!-- html5 color input -->
 @include('crud::fields.inc.wrapper_start')
-    <label>{!! $field['label'] !!}</label>
-    @include('crud::fields.inc.translatable_icon')
-    <input
-        type="text"
-        class="spectrum"
-        name="{{ $field['name'] }}"
-        value="{{ old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '' }}"
-        @include('crud::fields.inc.attributes')
-    >
+<label>{!! $field['label'] !!}</label>
+@include('crud::fields.inc.translatable_icon')
+<input
+    type="text"
+    class="spectrum"
+    data-show-alpha="{{$field['allows_alpha']?'true':'false'}}"
+    name="{{ $field['name'] }}"
+    value="{{ old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '' }}"
+    @include('crud::fields.inc.attributes')
+>
 
-    {{-- HINT --}}
-    @if (isset($field['hint']))
-        <p class="help-block">{!! $field['hint'] !!}</p>
-    @endif
+{{-- HINT --}}
+@if (isset($field['hint']))
+    <p class="help-block">{!! $field['hint'] !!}</p>
+@endif
 @include('crud::fields.inc.wrapper_end')
 
 {{-- ########################################## --}}
@@ -33,7 +34,6 @@
         <script>
             $("input.spectrum").spectrum({
                 preferredFormat: "hex6",
-                showAlpha: true,
                 showInput: true,
                 showInitial: true,
                 allowEmty: true,