/**
  * Implements hook_init().
  */
 function onRequest()
 {
     // On all Mollom administration pages, check the module configuration and
     // display the corresponding requirements error, if invalid.
     $url = Url::fromRoute('<current>');
     $current_path = $url->toString();
     if (empty($_POST) && strpos($current_path, 'admin/config/content/mollom') === 0 && \Drupal::currentUser()->hasPermission('administer mollom')) {
         // Re-check the status on the settings form only.
         $status = \Drupal\mollom\Utility\MollomUtilities::getAPIKeyStatus($current_path == 'admin/config/content/mollom/settings');
         if ($status !== TRUE) {
             // Fetch and display requirements error message, without re-checking.
             module_load_install('mollom');
             $requirements = mollom_requirements('runtime', FALSE);
             if (isset($requirements['mollom']['description'])) {
                 drupal_set_message($requirements['mollom']['description'], 'error');
             }
         }
     }
 }
예제 #2
0
 /**
  * Calls _mollom_status() directly to verify that current API keys are valid.
  */
 protected function assertValidKeys()
 {
     $status = MollomUtilities::getAPIKeyStatus(TRUE);
     $this->assertMollomWatchdogMessages();
     $this->assertIdentical($status['isVerified'], TRUE, t('Mollom servers can be contacted and testing API keys are valid.'));
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     $config = $this->config('mollom.settings');
     $config->set('keys.public', $values['keys']['public'])->set('keys.private', $values['keys']['private'])->set('fallback', $values['fallback'])->set('languages_expected', $values['languages_expected'])->set('privacy_link', $values['privacy_link'])->set('test_mode.enabled', $values['testing_mode'])->set('log_level', $values['log_level'])->set('captcha.audio.enabled', $values['audio_captcha_enabled'])->set('connection_timeout_seconds', $values['connection_timeout_seconds'])->save();
     parent::submitForm($form, $form_state);
     // Update Mollom site record with local configuration.
     MollomUtilities::getAPIKeyStatus(TRUE, TRUE);
 }
예제 #4
0
 /**
  * Gets the status of Mollom's API key configuration and also displays a
  * warning message if the Mollom API keys are not configured.
  *
  * To be used within the Mollom administration pages only.
  *
  * @param bool $force
  *   (optional) Boolean whether to ignore the cached state and re-check.
  *   Defaults to FALSE.
  * @param bool $update
  *   (optional) Whether to update Mollom with locally stored configuration.
  *   Defaults to FALSE.
  *
  * @return array
  *   An associative array describing the current status of the module:
  *   - isConfigured: Boolean whether Mollom API keys have been configured.
  *   - isVerified: Boolean whether Mollom API keys have been verified.
  *   - response: The response error code of the API verification request.
  *   - ...: The full site resource, as returned by the Mollom API.
  *
  * @see Mollom::getAPIKeyStatus().
  */
 public static function getAdminAPIKeyStatus($force = FALSE, $update = FALSE)
 {
     $status = MollomUtilities::getAPIKeyStatus($force, $update);
     if (empty($_POST) && !$status['isVerified']) {
         // Fetch and display requirements error message, without re-checking.
         module_load_install('mollom');
         $requirements = mollom_requirements('runtime', FALSE);
         if (isset($requirements['mollom']['description'])) {
             drupal_set_message($requirements['mollom']['description'], 'error');
         }
     }
     return $status;
 }