Skip to content

Commit

Permalink
Fix issue with setting values on timed field inputs
Browse files Browse the repository at this point in the history
Add configurable option to show/hide the config field in the CMS
Update Readme
  • Loading branch information
DorsetDigital committed Feb 17, 2021
1 parent e22afc6 commit e96caae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 8 additions & 4 deletions src/Model/RedirectRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<div id="' . $fieldType . '-fields">'));

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', '</div>');
$fields->addFieldsToTab('Root.Main', $formFields);
}
Expand All @@ -50,12 +57,9 @@ public function getCMSFields()
LiteralField::create('intro', '<p><strong>Select the rule type and save the record to start configuring.</strong></p>')
]);
}


}

$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;
Expand Down
10 changes: 6 additions & 4 deletions src/Model/Rule/TimedRuled.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e96caae

Please sign in to comment.