From: Vincent Vanwaelscappel Date: Mon, 12 Dec 2022 10:32:53 +0000 (+0100) Subject: wait #5626 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=6ed523785da2ab5608e891837061a6feb66f5332;p=cubist_cms-back.git wait #5626 @2 --- diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index 76abfaa..f578b7a 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -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); diff --git a/src/app/Magic/Fields/Integer.php b/src/app/Magic/Fields/Integer.php index 4924a81..85c76ee 100644 --- a/src/app/Magic/Fields/Integer.php +++ b/src/app/Magic/Fields/Integer.php @@ -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]); + } } diff --git a/src/app/Magic/Fields/Number.php b/src/app/Magic/Fields/Number.php index 2d23c2d..6917549 100644 --- a/src/app/Magic/Fields/Number.php +++ b/src/app/Magic/Fields/Number.php @@ -1,9 +1,7 @@ {'_' . $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]); } }