]> _ Git - cubist_cms-back.git/commitdiff
.
authorvince <vincent@enhydra.fr>
Sun, 14 Nov 2021 12:16:23 +0000 (13:16 +0100)
committervince <vincent@enhydra.fr>
Sun, 14 Nov 2021 12:16:23 +0000 (13:16 +0100)
src/app/Magic/Fields/Field.php
src/app/Magic/Fields/Textarea.php

index b5ed09e0bb594e680459c8db0e6ef1aea3aa8fc1..d5036afd0b4b911cec8436912278ab292bc17fd1 100644 (file)
@@ -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;
     }
 
index 3ee96f88014e13ab67f70b4aaafdc2855855f1e0..75f5c27a49b6585a5ac1d07c86353f797c6ac1d1 100644 (file)
@@ -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]);
+    }
 }