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
{
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();
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) {
$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);
<?php
-
namespace Cubist\Backpack\Magic\Fields;
-
class Number extends Field
{
protected $_adminType = 'number';
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]);
}
}