Browse Source

Form::timezone

jqh 5 years ago
parent
commit
915614e93d
3 changed files with 23 additions and 0 deletions
  1. 2 0
      src/Form.php
  2. 19 0
      src/Form/Field/Timezone.php
  3. 2 0
      src/Widgets/Form.php

+ 2 - 0
src/Form.php

@@ -74,6 +74,7 @@ use Dcat\Admin\Form\Concerns;
  * @method Field\Tree           tree($column, $label = '')
  * @method Field\Table          table($column, $callback)
  * @method Field\ListField      list($column, $label = '')
+ * @method Field\Timezone       timezone($column, $label = '')
  *
  * @method Field\BootstrapFile          bootstrapFile($column, $label = '')
  * @method Field\BootstrapImage         bootstrapImage($column, $label = '')
@@ -144,6 +145,7 @@ class Form implements Renderable
         'tree'           => Field\Tree::class,
         'table'          => Field\Table::class,
         'list'           => Field\ListField::class,
+        'timezone'       => Field\Timezone::class,
 
         'bootstrapFile'          => Field\BootstrapFile::class,
         'bootstrapImage'         => Field\BootstrapImage::class,

+ 19 - 0
src/Form/Field/Timezone.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace Dcat\Admin\Form\Field;
+
+use DateTimeZone;
+
+class Timezone extends Select
+{
+    protected $view = 'admin::form.select';
+
+    public function render()
+    {
+        $this->options = collect(DateTimeZone::listIdentifiers(DateTimeZone::ALL))->mapWithKeys(function ($timezone) {
+            return [$timezone => $timezone];
+        })->toArray();
+
+        return parent::render();
+    }
+}

+ 2 - 0
src/Widgets/Form.php

@@ -58,6 +58,8 @@ use Illuminate\Support\Str;
  * @method Field\MultipleImage  multipleImage($column, $label = '')
  * @method Field\Tree           tree($column, $label = '')
  * @method Field\Table          table($column, $callback)
+ * @method Field\ListField      list($column, $label = '')
+ * @method Field\Timezone       timezone($column, $label = '')
  *
  * @method Field\BootstrapFile          bootstrapFile($column, $label = '')
  * @method Field\BootstrapImage         bootstrapImage($column, $label = '')