You are here

private function AdminForm::checkSubmissionLimit in Webform CiviCRM Integration 8.5

Ajax-loaded mini-forms for the contributions tab.

1 call to AdminForm::checkSubmissionLimit()
AdminForm::buildContributionTab in src/AdminForm.php
Contribution settings

File

src/AdminForm.php, line 1406
Webform CiviCRM module's admin form.

Class

AdminForm
@file Webform CiviCRM module's admin form.

Namespace

Drupal\webform_civicrm

Code

private function checkSubmissionLimit() {

  // Bypass this until it is fully rescoped.
  return;
  $webform = $this->webform;

  /** @var \Drupal\webform\WebformAccessRulesManagerInterface $access_rules_manager */
  $access_rules_manager = \Drupal::service('webform.access_rules_manager');
  $anonymous_access = $access_rules_manager
    ->checkWebformAccess('create', new AnonymousUserSession(), $webform);

  // If anonymous users don't have access to the form, no need for a warning.
  if (!$anonymous_access
    ->isAllowed()) {
    return;
  }

  // @todo reevaluate these options in D8.
  return;

  // Handle ajax submission from "submit_limit" mini-form below
  if (!empty($_POST['submit_limit']) && !empty($_POST['submit_interval'])) {
    $submit_limit = (int) $_POST['submit_limit'];
    $submit_interval = (int) $_POST['submit_interval'];
    if ($submit_limit > 0 && $submit_interval != 0) {
      $webform['submit_limit'] = $submit_limit;
      $webform['submit_interval'] = $submit_interval;
      \Drupal::database()
        ->update('webform')
        ->condition('nid', $this->node->nid)
        ->fields([
        'submit_limit' => $submit_limit,
        'submit_interval' => $submit_interval,
      ])
        ->execute();
    }
    \Drupal::messenger()
      ->addStatus(t('Per-user submission limit has been updated. You may revisit these options any time on the <em>Form Settings</em> tab of this webform.'));
  }

  // Handle ajax submission from "webform_tracking_mode" mini-form below
  if (!empty($_POST['webform_tracking_mode']) && $_POST['webform_tracking_mode'] == 'strict') {
    \Drupal::state()
      ->set('webform_tracking_mode', 'strict');
    \Drupal::messenger()
      ->addStatus(t('Webform anonymous user tracking has been updated to use the strict method. You may revisit this option any time on the global <a :link>Webform Settings</a> page.', [
      ':link' => 'href="/admin/config/content/webform" target="_blank"',
    ]));
  }

  // Mini-form to configure submit limit without leaving the page
  if ($webform['submit_limit'] == -1) {
    $this->form['contribution']['sets']['submit_limit'] = [
      '#markup' => '<div class="messages warning">' . t('To prevent Credit Card abuse, it is recommended to set the per-user submission limit for this form.') . ' &nbsp; <button id="configure-submit-limit" type="button">' . t('Configure') . '</button>' . '<div id="submit-limit-wrapper" style="display:none">' . t('Limit each user to') . ' <input class="form-text" type="number" min="1" max="99" size="2" name="submit_limit"> ' . t('submission(s)') . ' <select class="form-select" name="submit_interval">' . '<option value="-1">' . t('ever') . '</option>' . '<option value="3600" selected="selected">' . t('every hour') . '</option>' . '<option value="86400">' . t('every day') . '</option>' . '<option value="604800">' . t('every week') . '</option>' . '</select> &nbsp; ' . ' <button id="configure-submit-limit-save" type="button">' . t('Save') . '</button>' . ' <button id="configure-submit-limit-cancel" type="button">' . t('Cancel') . '</button>' . '</div>' . '</div>',
    ];
  }
  elseif (\Drupal::state()
    ->get('webform_tracking_mode', 'cookie') == 'cookie') {
    $this->form['contribution']['sets']['webform_tracking_mode'] = [
      '#markup' => '<div class="messages warning">' . t('Per-user submission limit is enabled for this form, however the webform anonymous user tracking method is configured to use cookies only, which is not secure enough to prevent Credit Card abuse.') . ' <button id="webform-tracking-mode" type="button">' . t('Change Now') . '</button>' . ' <input type="hidden" value="" name="webform_tracking_mode"> ' . '</div>',
    ];
  }
}