]> _ Git - cubist_cms-back.git/commitdiff
wait #5625 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 5 Dec 2022 14:35:37 +0000 (15:35 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 5 Dec 2022 14:35:37 +0000 (15:35 +0100)
src/app/Magic/Fields/Date.php
src/app/Magic/Fields/Datetime.php
src/app/Magic/Fields/Field.php
src/resources/views/fields/authhidden.blade.php
src/resources/views/fields/noteditable.blade.php [new file with mode: 0644]

index f6f986c8af2d9c3da065c945583dca0b3e24570f..9ed2c5f25a194b302b32f9033373831c1e2d7ae6 100644 (file)
@@ -10,4 +10,5 @@ class Date extends Datetime
     protected $_cast = 'date';
     protected $_columnType = 'date';
     protected $_columnFormat = 'YYYY-MM-DD';
+    protected $_pickerFormat = 'yyyy-mm-dd';
 }
index 3c61d486b375a610f3c6906dc01db1187dea15da..e5a7c655c2fe267deba9b249b61700cf4bd2be8e 100644 (file)
@@ -3,11 +3,14 @@
 
 namespace Cubist\Backpack\Magic\Fields;
 
+use Cubist\Backpack\Facades\App;
+use Illuminate\Support\Facades\Session;
+
 class Datetime extends Field
 {
     protected $_adminType = 'datetime_picker';
     protected $_cast = 'datetime';
-    protected $pickerOptions = ['format' => 'DD/MM/YYYY HH:mm', 'language' => 'fr'];
+    protected $_pickerFormat = 'yyyy-mm-dd hh:ii';
     protected $_databaseType = 'datetime';
     protected $_databaseIndex = true;
     protected $_columnType = 'datetime';
@@ -21,6 +24,18 @@ class Datetime extends Field
 
     public function getDefaultAttributes()
     {
-        return array_merge(parent::getDefaultAttributes(), ['datetime_picker_options' => $this->pickerOptions]);
+        return array_merge(parent::getDefaultAttributes(), ['picker_format' => $this->_pickerFormat]);
+    }
+
+    protected function _postSetAttributes()
+    {
+        parent::_postSetAttributes();
+        $this->setAttributeIfNotSet('datetime_picker_options', $this->_getDatePickerOptions());
+        $this->setAttributeIfNotSet('date_picker_options', $this->_getDatePickerOptions());
+    }
+
+    protected function _getDatePickerOptions()
+    {
+        return ['format' => $this->getAttribute('picker_format'), 'language' => __('fr'), 'todayHighlight' => true];
     }
 }
index 6227586489b15b8352912b69fed7dfe27475d824..76abfaa7bad94823f0e0c98709b14f10e8f3f353 100644 (file)
@@ -397,6 +397,15 @@ class Field implements \ArrayAccess
     {
         if (null !== $this->getAttribute('can', null)) {
             if (!self::can($this->getAttribute('can'))) {
+                $this->setAttribute('preview', false);
+                $this->setAttribute('filter', false);
+                $this->setAttribute('column', false);
+                $this->setAttribute('auth', false);
+                $this->setAttribute('type', 'noteditable');
+                $this->setAttribute('view_namespace', CubistBackpackServiceProvider::NAMESPACE . '::fields');
+            }
+        }else if (null !== $this->getAttribute('can_hidden', null)) {
+            if (!self::can($this->getAttribute('can_hidden'))) {
                 $this->setAttribute('preview', false);
                 $this->setAttribute('filter', false);
                 $this->setAttribute('column', false);
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..71052fad9d6664f6af6e4259fb1739e058fd9d4b 100644 (file)
@@ -0,0 +1,18 @@
+@php
+    // if not otherwise specified, the hidden input should take up no space in the form
+  $field['wrapper']['class'] = $field['wrapper']['class'] ?? $field['wrapperAttributes']['class'] ?? "hidden";
+  $v=old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '';
+  if(!is_string($v)){
+      $v=json_encode($v);
+  }
+@endphp
+
+    <!-- hidden input -->
+@include('crud::fields.inc.wrapper_start')
+<input
+    type="hidden"
+    name="{{ $field['name'] }}"
+    value="{{ $v }}"
+    @include('crud::fields.inc.attributes')
+>
+@include('crud::fields.inc.wrapper_end')
diff --git a/src/resources/views/fields/noteditable.blade.php b/src/resources/views/fields/noteditable.blade.php
new file mode 100644 (file)
index 0000000..e69de29