]> _ Git - cubist_cms-back.git/commitdiff
wip #3753 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 4 Nov 2021 18:54:57 +0000 (19:54 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 4 Nov 2021 18:54:57 +0000 (19:54 +0100)
src/app/Magic/Fields/Field.php
src/app/Magic/Fields/ReadOnlyValue.php

index 8eacc2174b3d7e1cdc97a48254106cce341cc976..cfc37ad87a9ed52e962255a9ae27463d932b946d 100644 (file)
@@ -37,6 +37,7 @@ class Field implements \ArrayAccess
     protected $_columnViewNamespace = 'crud::columns';
     protected $_searchLogic = 'text';
 
+    protected $_readOnly = false;
     protected $_databaseType = 'text';
     protected $_databaseUnique = false;
     protected $_databaseIndex = false;
@@ -134,6 +135,7 @@ class Field implements \ArrayAccess
     {
         return [
             'type' => $this->_adminType, 'view_namespace' => $this->_viewNamespace, 'column' => false, 'form' => 'both', 'rules' => '',
+            'read_only' => $this->_readOnly,
             'prefix' => $this->_prefix, 'suffix' => $this->_suffix,
             'fillable' => true, 'guarded' => false, 'hidden' => false,
             'filter' => false, 'filter_type' => $this->_filterType, 'filter_label' => null, 'filter_values' => $this->_filterValues,
@@ -174,7 +176,12 @@ class Field implements \ArrayAccess
     public function getDefinition()
     {
         $this->_preGetDefinition();
-        return $this->_attributes;
+        $res = $this->_attributes;
+        if ($this->getAttribute('read_only', false)) {
+            $res['view_namespace'] = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+            $res['type'] = 'static_value';
+        }
+        return $res;
     }
 
     protected function _preGetDefinition()
@@ -298,7 +305,7 @@ class Field implements \ArrayAccess
 
         $default = $this->getAttribute('database_default') ?? $this->getAttribute('default');
         if ($default !== null) {
-            $attributes['default']=$default;
+            $attributes['default'] = $default;
         }
 
         $table->addColumn($name,
index 12d0a7781ea2fa8720d267b6bd5f06f3d914f672..7088e6831b5c386338a0fd0c58811624b8588942 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace Cubist\Backpack\Magic\Fields;
 
-class ReadOnlyValue extends StaticValue
+class ReadOnlyValue extends LongText
 {
-    protected $_databaseType = 'text';
+    protected $_readOnly = true;
 }