]> _ Git - cubist_cms-back.git/commitdiff
wait #5626 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 12 Dec 2022 10:32:53 +0000 (11:32 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 12 Dec 2022 10:32:53 +0000 (11:32 +0100)
src/app/Magic/Fields/Field.php
src/app/Magic/Fields/Integer.php
src/app/Magic/Fields/Number.php

index 76abfaa7bad94823f0e0c98709b14f10e8f3f353..f578b7ae83c20c21025b6d663a412f912a6954b2 100644 (file)
@@ -3,14 +3,14 @@
 
 namespace Cubist\Backpack\Magic\Fields;
 
+use Cubist\Backpack\CubistBackpackServiceProvider;
 use Cubist\Backpack\CubistCrudPanel;
 use Cubist\Backpack\Magic\CubistMagicAttribute;
-use Cubist\Backpack\CubistBackpackServiceProvider;
+use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
 use Doctrine\DBAL\Schema\Table;
 use Exception;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Str;
-use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
 
 class Field implements \ArrayAccess
 {
@@ -161,9 +161,15 @@ class Field implements \ArrayAccess
 
     public function __construct($attributes)
     {
+
+        $attributes = Arr::undot($attributes);
         $this->_attributes = $this->getDefaultAttributes();
 
+        $merge = ['attributes'];
         foreach ($attributes as $attribute => $value) {
+            if (in_array($attribute, $merge) && isset($this->_attributes[$attribute]) && is_array($this->_attributes[$attribute]) && is_array($value)) {
+                $value = array_merge($this->_attributes[$attribute], $value);
+            }
             $this->setAttribute($attribute, $value);
         }
         $this->_postSetAttributes();
@@ -195,11 +201,16 @@ class Field implements \ArrayAccess
         return $res;
     }
 
+    protected function _getFieldAttributesKeys()
+    {
+        return ['placeholder', 'rows', 'pattern'];
+    }
+
     protected function getFieldAttributes()
     {
         $res = [];
 
-        $fieldAttributes = ['placeholder', 'rows', 'pattern'];
+        $fieldAttributes = $this->_getFieldAttributesKeys();
 
         foreach ($this->_attributes as $k => $v) {
             if (null === $v) {
@@ -404,7 +415,7 @@ class Field implements \ArrayAccess
                 $this->setAttribute('type', 'noteditable');
                 $this->setAttribute('view_namespace', CubistBackpackServiceProvider::NAMESPACE . '::fields');
             }
-        }else if (null !== $this->getAttribute('can_hidden', null)) {
+        } else if (null !== $this->getAttribute('can_hidden', null)) {
             if (!self::can($this->getAttribute('can_hidden'))) {
                 $this->setAttribute('preview', false);
                 $this->setAttribute('filter', false);
index 4924a810dc019acebc9a5f9c7641c8b2e02f63bc..85c76ee38f11b740bc2f7a4d7cf919c85ee50c38 100644 (file)
@@ -7,4 +7,9 @@ namespace Cubist\Backpack\Magic\Fields;
 class Integer extends Number
 {
     protected $_step = 1;
+
+    public function getColumnData()
+    {
+        return array_merge(parent::getColumnData(), ['decimals' => 0]);
+    }
 }
index 2d23c2d4253b43174f64f9cf06739e6683f8d3e9..69175494f5bd7ba07ae16a2343e9c608147d26a1 100644 (file)
@@ -1,9 +1,7 @@
 <?php
 
-
 namespace Cubist\Backpack\Magic\Fields;
 
-
 class Number extends Field
 {
     protected $_adminType = 'number';
@@ -14,24 +12,28 @@ class Number extends Field
     protected $_max = null;
     protected $_lang = 'en-150';
 
+
     public function getDefaultAttributes()
     {
-        $res = parent::getDefaultAttributes();
-        $attrs = ['min', 'max', 'step', 'lang'];
-        $defaults = [];
-        foreach ($attrs as $attr) {
-            if (null === $this->{'_' . $attr}) {
-                continue;
-            }
-            $defaults[$attr] = $this->{'_' . $attr};
-        }
-
-        $res['attributes'] = array_merge($defaults, $res['attributes']);
+        $collection = '_TBD_';
+        $res = array_merge(parent::getDefaultAttributes(), [
+            'min' => $this->_min,
+            'max' => $this->_max,
+            'step' => $this->_step,
+            'lang' => $this->_lang,
+        ]);
+
         return $res;
     }
 
+    protected function _getFieldAttributesKeys()
+    {
+        return array_merge(parent::_getFieldAttributesKeys(), ['min', 'max', 'step', 'lang']);
+    }
+
+
     public function getColumnData()
     {
-        return array_merge(parent::getColumnData(), ['thousands_sep' => '']);
+        return array_merge(parent::getColumnData(), ['thousands_sep' => '', 'decimals' => 2]);
     }
 }