From: Vincent Vanwaelscappel Date: Thu, 4 Nov 2021 18:54:57 +0000 (+0100) Subject: wip #3753 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=c81fef934f8fa3dd22c8ba3e370d60b4541ec21c;p=cubist_cms-back.git wip #3753 @1 --- diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index 8eacc21..cfc37ad 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -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, diff --git a/src/app/Magic/Fields/ReadOnlyValue.php b/src/app/Magic/Fields/ReadOnlyValue.php index 12d0a77..7088e68 100644 --- a/src/app/Magic/Fields/ReadOnlyValue.php +++ b/src/app/Magic/Fields/ReadOnlyValue.php @@ -2,7 +2,7 @@ namespace Cubist\Backpack\Magic\Fields; -class ReadOnlyValue extends StaticValue +class ReadOnlyValue extends LongText { - protected $_databaseType = 'text'; + protected $_readOnly = true; }