Beispiel #1
0
 /**
  * Submit handler for feedback options.
  */
 public static function addFeedbackOptionsSubmit(&$form, FormStateInterface &$form_state)
 {
     $forms = FormController::getProtectedForms();
     $mollom_form = Form::load($forms['delete'][$form_state->getFormObject()->getFormId()])->initialize();
     $entity_type = $mollom_form['entity'];
     if (!empty($entity_type)) {
         $id = $form_state->getFormObject()->getEntity()->id();
     } else {
         $id = $form_state->getValue($mollom_form['mapping']['post_id']);
     }
     $feedback = $form_state->getValue(array('mollom', 'feedback'));
     if (!empty($feedback)) {
         if (self::sendFeedback($entity_type, $id, $feedback, 'moderate', 'mollom_data_delete_form_submit')) {
             drupal_set_message(t('The content was successfully reported as inappropriate.'));
         }
     }
     // Remove Mollom session data.
     ResponseDataStorage::delete($entity_type, $id);
 }
Beispiel #2
0
 /**
  * Returns a cached mapping of protected and delete confirmation form ids.
  *
  * @param $reset
  *   (optional) Boolean whether to reset the static cache, flush the database
  *   cache, and return nothing (TRUE). Defaults to FALSE.
  *
  * @return
  *   An associative array containing:
  *   - protected: An associative array whose keys are protected form IDs and
  *     whose values are the corresponding module names the form belongs to.
  *   - delete: An associative array whose keys are 'delete form' ids and whose
  *     values are protected form ids; e.g.
  * @code
  *     array(
  *       'node_delete_confirm' => 'article_node_form',
  *     )
  * @endcode
  *     A single delete confirmation form id can map to multiple registered
  *     $form_ids, but only the first is taken into account. As in above example,
  *     we assume that all 'TYPE_node_form' definitions belong to the same entity
  *     and therefore have an identical 'post_id' mapping.
  */
 public static function getProtectedForms($reset = FALSE)
 {
     $forms =& drupal_static(__FUNCTION__);
     if ($reset) {
         unset($forms);
         return true;
     }
     if (isset($forms)) {
         return $forms;
     }
     // Get all forms that are protected
     $protected_forms = \Drupal\mollom\Entity\Form::loadMultiple();
     foreach ($protected_forms as $form_id => $info) {
         $forms['protected'][$form_id] = $info->get('module');
     }
     // Build a list of delete confirmation forms of entities integrating with
     // Mollom, so we are able to alter the delete confirmation form to display
     // our feedback options.
     $forms['delete'] = array();
     foreach (self::getProtectableForms() as $form_id => $info) {
         if (!isset($info['delete form']) || !isset($info['entity'])) {
             continue;
         }
         // We expect that the same delete confirmation form uses the same form
         // element mapping, so multiple 'delete form' definitions are only processed
         // once. Additionally, we only care for protected forms.
         if (!isset($forms['delete'][$info['delete form']]) && isset($forms['protected'][$form_id])) {
             // A delete confirmation form integration requires a 'post_id' mapping.
             $form_info = self::getProtectedFormDetails($form_id, $info['module']);
             if (isset($form_info['mapping']['post_id'])) {
                 $forms['delete'][$info['delete form']] = $form_id;
             }
         }
     }
     return $forms;
 }
Beispiel #3
0
 /**
  * Saves a mollom_form entity to protect a given form with Mollom.
  *
  * @param string $form_id
  *   The form id to protect.
  * @param int $mode
  *   The protection mode defined in \Drupal\mollom\Entity\FormInterface.
  *   Defaults to MOLLOM_MODE_ANALYSIS.
  * @param array $values
  *   (optional) An associative array of properties to additionally set on the
  *   mollom_form entity.
  *
  * @return int
  *   The save status, as returned by mollom_form_save().
  */
 protected function setProtection($form_id, $mode = FormInterface::MOLLOM_MODE_ANALYSIS, $values = array())
 {
     /* @var $mollom_form \Drupal\mollom\Entity\FormInterface */
     if (!($mollom_form = \Drupal::entityManager()->getStorage('mollom_form')->load($form_id))) {
         $mollom_form = Form::create();
         $mollom_form->initialize($form_id);
     }
     $mollom_form->setProtectionMode($mode);
     if ($values) {
         foreach ($values as $property => $value) {
             $mollom_form[$property] = $value;
         }
     }
     $status = $mollom_form->save();
     return $status;
 }
 /**
  * Tests invalid (stale) form configurations.
  */
 function testInvalidForms()
 {
     $forms = ['nonexisting' => 'nonexisting_form', 'user' => 'user_nonexisting_form', 'node' => 'nonexisting_node_form', 'comment' => 'comment_node_nonexisting_form'];
     $mode = 0;
     foreach ($forms as $module => $form_id) {
         $mollom_form = FormController::getProtectedFormDetails($form_id, $module, []);
         $mollom_form['mode'] = $mode++;
         $form = Form::create($mollom_form);
         $form->id = $form_id;
         $form->save();
     }
     // Just visiting the form administration page is sufficient; it will throw
     // fatal errors, warnings, and notices.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('admin/config/content/mollom');
     // Ensure that unprotecting the forms does not throw any notices either.
     foreach ($forms as $form_id) {
         $this->assertNoLinkByHref('admin/config/content/mollom/form/' . $form_id . '/edit');
         $this->assertLinkByHref('admin/config/content/mollom/form/' . $form_id . '/delete');
         $this->drupalPostForm('admin/config/content/mollom/form/' . $form_id . '/delete', array(), t('Remove Mollom Protection'));
         $this->assertNoLinkByHref('admin/config/content/mollom/form/' . $form_id . '/delete');
     }
     // Confirm deletion.
     $configured = \Drupal::entityManager()->getStorage('mollom_form')->loadMultiple();
     $this->assertFalse($configured, 'No forms found.');
 }
 /**
  * Saves a mollom_form entity to protect a given form with Mollom.
  *
  * @param string $form_id
  *   The form id to protect.
  * @param int $mode
  *   The protection mode defined in \Drupal\mollom\Entity\FormInterface.
  *   Defaults to MOLLOM_MODE_ANALYSIS.
  * @param array $values
  *   (optional) An associative array of properties to additionally set on the
  *   mollom_form entity.
  *
  * @return int
  *   The save status, as returned by mollom_form_save().
  */
 protected function setProtection($form_id, $mode = FormInterface::MOLLOM_MODE_ANALYSIS, $values = array())
 {
     if (!($mollom_form = entity_load('mollom_form', $form_id))) {
         $mollom_form = Form::create();
         $mollom_form->initialize($form_id);
     }
     $mollom_form->setProtectionMode($mode);
     if ($values) {
         foreach ($values as $property => $value) {
             $mollom_form[$property] = $value;
         }
     }
     $status = $mollom_form->save();
     return $status;
 }