diff --git a/controllers/Countries.php b/controllers/Countries.php index 40e5fc6..86b1966 100644 --- a/controllers/Countries.php +++ b/controllers/Countries.php @@ -1,5 +1,6 @@ <?php namespace Winter\Test\Controllers; +use Request; use BackendMenu; use Backend\Classes\Controller; @@ -24,4 +25,27 @@ public function __construct() BackendMenu::setContext('Winter.Test', 'test', 'countries'); } + + public function formExtendFields($form) + { + if (!$form->isNested && $form->model instanceof \October\Test\Models\Country) { + $isActive = false; + if (Request::ajax()) { + $isActive = input('Country[is_active]', false); + } elseif ($form->model->exists) { + $isActive = $form->model->is_active; + } + + if ($isActive) { + $form->addFields([ + 'dynamic_flags' => [ + 'label' => 'Active Flags (Dynamic Fileupload Field)', + 'type' => 'fileupload', + 'mode' => 'image', + 'span' => 'right', + ], + ]); + } + } + } } diff --git a/models/Country.php b/models/Country.php index 24acbfb..b863d65 100644 --- a/models/Country.php +++ b/models/Country.php @@ -39,6 +39,10 @@ class Country extends Model 'conditions' => "type = 'general.type'" ], ]; + public $attachMany = [ + 'flags' => ['System\Models\File'], + 'dynamic_flags' => ['System\Models\File'], + ]; /** * Softly implement the TranslatableModel behavior. diff --git a/models/country/fields.yaml b/models/country/fields.yaml index 57e0edf..ec444d6 100644 --- a/models/country/fields.yaml +++ b/models/country/fields.yaml @@ -16,11 +16,20 @@ fields: field: name type: slug + flags: + label: Flags (Static Fileupload Field) + type: fileupload + mode: image + span: full + is_active: label: Active comment: Check this box to hide some tabs, using depends and trigger API. type: checkbox + span: left default: true + attributes: + onchange: "$(this).request('form::onRefresh');" tabs: lazy: