Skip to content
This repository has been archived by the owner on Feb 23, 2020. It is now read-only.

Current time defaults #172

Open
wants to merge 2 commits into
base: 8.x-1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/Plugin/Condition/CurrentTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CurrentTime extends ConditionPluginBase {
public function defaultConfiguration() {
return [
'date' => NULL,
'enable' => FALSE,
] + parent::defaultConfiguration();
}

Expand All @@ -55,6 +56,12 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#weight' => 50,
);

$form['enable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable this condition?'),
'#default_value' => $this->getConfiguration()['enable'],
];

$form['negate'] = array(
'#type' => 'radios',
'#title' => $this->t('Timing'),
Expand All @@ -74,13 +81,15 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
if ($date = $form_state->getValue('date')) {
$this->configuration['date'] = $date->format('U');
}
else {
$this->configuration['date'] = NULL;
// Disable saving this plugin if it is not actively enabled.
$enabled = $form_state->getValue('enable');
if (!$enabled) {
return;
}
$this->setConfig('enable', $enabled);
$this->setConfig('date', $form_state->getValue('date')->format('U'));
parent::submitConfigurationForm($form, $form_state);

}

/**
Expand Down