diff --git a/src/Plugin/Condition/CurrentTime.php b/src/Plugin/Condition/CurrentTime.php index fa03886..d8811ba 100644 --- a/src/Plugin/Condition/CurrentTime.php +++ b/src/Plugin/Condition/CurrentTime.php @@ -29,6 +29,7 @@ class CurrentTime extends ConditionPluginBase { public function defaultConfiguration() { return [ 'date' => NULL, + 'enable' => FALSE, ] + parent::defaultConfiguration(); } @@ -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'), @@ -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); + } /**