From e96caaed771584e0a6f614995687ce080738ee29 Mon Sep 17 00:00:00 2001 From: Tim Burt Date: Wed, 17 Feb 2021 14:26:35 +0000 Subject: [PATCH] Fix issue with setting values on timed field inputs Add configurable option to show/hide the config field in the CMS Update Readme --- README.md | 2 -- src/Model/RedirectRule.php | 12 ++++++++---- src/Model/Rule/TimedRuled.php | 10 ++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c4765d0..4009c4a 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,6 @@ Screenshots of the QR preview, redirect editing and rule editing screens can be # ToDo * Add internationalisation to all fields / content -* Complete time-based redirection rule -* Suppress rule confguration data in CMS * Add ability to enable / disable specific rule types using the configuration API * Add download option for generated QR at large size / high res * Finish docs diff --git a/src/Model/RedirectRule.php b/src/Model/RedirectRule.php index 87f477f..9cf3784 100644 --- a/src/Model/RedirectRule.php +++ b/src/Model/RedirectRule.php @@ -39,8 +39,15 @@ public function getCMSFields() if (($savedRule) && ($this->RuleType == $fieldType)) { $rule = $fact->getRule($this); $formFields = $rule->getFormFields(); - if ((is_array($formFields)) && (count($formFields) > 0)) { + if (is_array($formFields)) { array_unshift($formFields, LiteralField::create($fieldType . '-fields-open', '
')); + + if ($this->config()->get('show_config_field') === true) { + $fields->dataFieldByName('RuleConfig')->setRows(2)->setReadOnly(true); + } else { + $fields->removeByName('RuleConfig'); + } + $formFields[] = LiteralField::create($fieldType . '-fields-close', '
'); $fields->addFieldsToTab('Root.Main', $formFields); } @@ -50,12 +57,9 @@ public function getCMSFields() LiteralField::create('intro', '

Select the rule type and save the record to start configuring.

') ]); } - - } $fields->removeByName(['SortOrder', 'RedirectID']); - $fields->dataFieldByName('RuleConfig')->setRows(2)->setReadOnly(true); $fields->dataFieldByName('RedirectTo')->setDescription('The full URL of the redirect, eg. https://www.example.com'); return $fields; diff --git a/src/Model/Rule/TimedRuled.php b/src/Model/Rule/TimedRuled.php index 3682814..87320ee 100644 --- a/src/Model/Rule/TimedRuled.php +++ b/src/Model/Rule/TimedRuled.php @@ -42,14 +42,16 @@ public function getFormFields() $configJSON = $this->getConfig(); $config = json_decode($configJSON, true); - $fromField = DatetimeField::create('FromTime', 'Start date/time'); - $toField = DatetimeField::create('ToTime', 'End date/time'); + $fromField = DatetimeField::create('FromTime', 'Start date/time')->setHTML5(true); + $toField = DatetimeField::create('ToTime', 'End date/time')->setHTML5(true); if (isset($config['from'])) { - $fromField->setValue($config['from']); + $fromValue = (string) $config['from'].":00"; + $fromField->setValue($fromValue); } if (isset($config['to'])) { - $toField->setValue($config['to']); + $toValue = (string) $config['to'].":00"; + $toField->setValue($toValue); } $fields[] = $fromField;