/**
  * Form submit handler for mollom_report_form().
  */
 public function submit($form, &$form_state)
 {
     if ($form_state['values']['confirm']) {
         $entity = $form_state['values']['entity'];
         $id = $form_state['values']['id'];
         // Load the Mollom session data.
         $data = mollom_data_load($entity, $id);
         // Send feedback to Mollom, if we have session data.
         if ((!empty($data->contentId) || !empty($data->captchaId)) && !empty($form_state['values']['mollom']['feedback'])) {
             if (_mollom_send_feedback($data, $form_state['values']['mollom']['feedback'], 'moderate', 'mollom_report_form_submit')) {
                 drupal_set_message(t('The content was successfully reported as inappropriate.'));
             }
         }
         // Delete the content. The callback should take care of proper deletion and
         // cache clearing on its own.
         foreach (mollom_form_list() as $form_id => $info) {
             if (!isset($info['entity']) || $info['entity'] != $entity) {
                 continue;
             }
             // If there is a 'report delete callback', invoke it.
             if (isset($info['report delete callback']) && function_exists($info['report delete callback'])) {
                 $function = $info['report delete callback'];
                 $function($entity, $id);
                 break;
             }
         }
         $form_state['redirect'] = '<front>';
     }
 }
 /**
  * Menu access callback; Determine access to report to Mollom.
  *
  * The special $entity type "session" may be used for mails and messages, which
  * originate from form submissions protected by Mollom, and can be reported by
  * anyone; $id is expected to be a Mollom session id instead of an entity id
  * then.
  *
  * @param $entity
  *   The entity type of the data to report.
  * @param $id
  *   The entity id of the data to report.
  *
  * @todo Revamp this based on new {mollom}.form_id info.
  */
 function reportAccess($entity, $id)
 {
     // The special entity 'session' means that $id is a Mollom session_id, which
     // can always be reported by everyone.
     if ($entity == 'session') {
         return !empty($id) ? TRUE : FALSE;
     }
     // Retrieve information about all protectable forms. We use the first valid
     // definition, because we assume that multiple form definitions just denote
     // variations of the same entity (e.g. node content types).
     foreach (mollom_form_list() as $form_id => $info) {
         if (!isset($info['entity']) || $info['entity'] != $entity) {
             continue;
         }
         // If there is a 'report access callback', invoke it.
         if (isset($info['report access callback']) && function_exists($info['report access callback'])) {
             $function = $info['report access callback'];
             return $function($entity, $id);
         }
         // Otherwise, if there is a 'report access' list of permissions, iterate
         // over them.
         if (isset($info['report access'])) {
             foreach ($info['report access'] as $permission) {
                 if (\Drupal::currentUser()->hasPermission($permission)) {
                     return TRUE;
                 }
             }
         }
     }
     // If we end up here, then the current user is not permitted to report this
     // content.
     return FALSE;
 }