Example #1
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;
 }