From 3f7903705da45ec677c37f3011924bc19f8d5c7e Mon Sep 17 00:00:00 2001 From: vince Date: Sun, 14 Nov 2021 13:16:23 +0100 Subject: [PATCH] . --- src/app/Magic/Fields/Field.php | 23 ++++++++++++++++++++++- src/app/Magic/Fields/Textarea.php | 6 ++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index b5ed09e..d5036af 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -8,6 +8,7 @@ use Cubist\Backpack\Magic\CubistMagicAttribute; use Cubist\Backpack\CubistBackpackServiceProvider; use Doctrine\DBAL\Schema\Table; use Exception; +use Illuminate\Support\Arr; use Illuminate\Support\Str; use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel; @@ -32,6 +33,8 @@ class Field implements \ArrayAccess protected $_prefix = null; protected $_suffix = null; + protected $_placeholder = null; + protected $_adminType = 'text'; protected $_viewNamespace = 'crud::fields'; protected $_columnViewNamespace = 'crud::columns'; @@ -147,7 +150,9 @@ class Field implements \ArrayAccess 'allow_null' => true, 'can' => $this->_can, 'can_write' => $this->_canWrite, 'auth' => $this->_auth, 'database_type' => $this->_databaseType, 'database_unique' => $this->_databaseUnique, 'database_index' => $this->_databaseIndex, 'database_default' => $this->_databaseDefault, 'database_length' => $this->_databaseLength, - 'fake' => false, 'store_in' => 'extras', 'attributes' => []]; + 'fake' => false, 'store_in' => 'extras', 'attributes' => [], + 'field_attributes.placeholder' => $this->_placeholder, + ]; } public function __construct($attributes) @@ -182,6 +187,22 @@ class Field implements \ArrayAccess $res['view_namespace'] = CubistBackpackServiceProvider::NAMESPACE . '::fields'; $res['type'] = 'static_value'; } + $res['attributes'] = $this->getFieldAttributes(); + return $res; + } + + protected function getFieldAttributes() + { + $res = []; + foreach ($this->_attributes as $k => $v) { + if (null === $v) { + continue; + } + if (strstr($k, 'field_attributes.')) { + $e = explode('.', $k, 2); + Arr::set($res, $e[1], $v); + } + } return $res; } diff --git a/src/app/Magic/Fields/Textarea.php b/src/app/Magic/Fields/Textarea.php index 3ee96f8..75f5c27 100644 --- a/src/app/Magic/Fields/Textarea.php +++ b/src/app/Magic/Fields/Textarea.php @@ -13,4 +13,10 @@ class Textarea extends Field protected $_translatable = true; protected $_columnType = 'textarea'; protected $_columnViewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::columns'; + protected $_fieldHeight = 15; + + public function getDefaultAttributes() + { + return array_merge(parent::getDefaultAttributes(), ['field_attributes.rows' => $this->_fieldHeight]); + } } -- 2.39.5