Commit 1b11a41f authored by Binny Thomas's avatar Binny Thomas Committed by Binny Thomas
Browse files

Issue #3310326 by binnythomas: Port the affiliate user settings configuration form to Drupal 9

parent f8df1c12
Loading
Loading
Loading
Loading
+151 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\uber_affiliate\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * PayoutForm.
 */
class UserConfigForm extends ConfigFormBase {

  /**
   * Config settings.
   *
   * @var string
   */
  const SETTINGS = 'uber_affiliate.userconfigform.settings';

  /**
   * Required by FormBase.
   */
  public function getFormId() {
    return 'uber_affiliate_user_config_form';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      static::SETTINGS,
    ];
  }

  /**
   * PayoutForm.
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    $form['affiliate_module_settings']['configuration']['limits'] = array(
      '#type' => 'fieldset',
      '#title' => t('Restrictions and limitations'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['affiliate_module_settings']['configuration']['limits']['affiliate_module_allow_all_users'] = array(
      '#type' => 'radios',
      '#title' => t('All users are affiliates'),
      '#default_value' => \Drupal::state()->get('affiliate_module_allow_all_users', 0),
      '#options' => array(0 => t('No'), 1 => t('Yes')),
      '#description' => t('If selected, anyone with an active account on this site will receive credit for referring an outside user to any path as configured on the <a href="@content_settings_form">content settings form</a>.', array('@content_settings_form' => base_path() . 'admin/config/people/affiliate/content')),
    );
    $form['affiliate_module_settings']['configuration']['limits']['affiliate_module_check_referrer'] = array(
      '#type' => 'radios',
      '#title' => t('Always check for referring URL'),
      '#default_value' => \Drupal::state()->get('affiliate_module_check_referrer', 1),
      '#options' => array(0 => t('No'), 1 => t('Yes')),
      '#description' => t('If enabled, affiliates will not receive credit unless the user who visits the link first clicks on a link from another website. In other words, if the visitor types the URL directly into their browser instead of clicking on a link somewhere, they will still be taken to the destination page but the affiliate whose link they visited will not receive credit for that visit. Enabled by default.'),
    );
    $form['affiliate_module_settings']['configuration']['limits']['affiliate_module_click_ignore_enable'] = array(
      '#type' => 'radios',
      '#title' => t('Enable IP click ignore'),
      '#default_value' => \Drupal::state()->get('affiliate_module_click_ignore_enable', 0),
      '#options' => array(0 => t('Disable'), 1 => t('Enable')),
      '#description' => t('If you wish to ignore clicks from the same IP address within a given time period, enable this option.'),
    );
    $form['affiliate_module_settings']['configuration']['limits']['affiliate_module_click_ignore_interval'] = array(
      '#type' => 'select',
      '#title' => t('IP click ignore time limit'),
      '#default_value' =>\Drupal::state()->get('affiliate_module_click_ignore_interval', 86400),
      '#options' => array_map('format_interval', array_combine(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200)),
      '#description' => t('Ignore clicks from the same IP address for this time interval.'),
      '#states' => array(
        'invisible' => array(
          ':input[name="affiliate_module_click_ignore_enable"]' => array('value' => 0),
        ),
      ),
    );
    $form['affiliate_module_settings']['configuration']['limits']['affiliate_module_ignored_uri_referrers'] = array(
      '#type' => 'textarea',
      '#title' => t('Ignore clicks referred by these URLs'),
      '#default_value' => \Drupal::state()->get('affiliate_module_ignored_uri_referrers', ''),
      '#size' => 70,
      '#rows' => 4,
      '#description' => t('List all referring URL sources, each on a new line, that will be ignored by the affiliate system if a click-thru originates from that source.'),
    );
    $form['affiliate_module_settings']['configuration']['limits']['affiliate_module_ignored_ips'] = array(
      '#type' => 'textarea',
      '#title' => t('Ignore clicks originating from these IP addresses'),
      '#default_value' => \Drupal::state()->get('affiliate_module_ignored_ips', ''),
      '#size' => 70,
      '#rows' => 4,
      '#description' => t('List all IP addresses, each on a new line, that will be ignored by the affiliate system when the IP address of the user who has clicked through matches any of the IP addresses on this list.'),
    );
    $form['affiliate_module_settings']['configuration']['limits']['affiliate_module_ignored_users'] = array(
      '#type' => 'textarea',
      '#title' => t('Denied by User'),
      '#default_value' => \Drupal::state()->get('affiliate_module_ignored_users', ''),
      '#size' => 70,
      '#rows' => 4,
      '#description' => t('List all user names, each on a new line, that will be ignored by the affiliate system if a click-thru originates from a user with that same user name. NOTE: currently logged-in users who click on their own links will be ignored automatically, regardless of whether their name appears in this or not.'),
    );
    $form['affiliate_module_settings']['configuration']['top_users'] = array(
      '#type' => 'fieldset',
      '#title' => t('Top Users'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['affiliate_module_settings']['configuration']['top_users']['affiliate_module_top_users_count_page'] = array(
      '#type' => 'select',
      '#title' => t('Top Users Count For Page'),
      '#default_value' => \Drupal::state()->get('affiliate_module_top_users_count_page', 5),
      '#options' => array(5 => 5, 10 => 10, 25 => 25, 50 => 50, 100 => 100),
      '#description' => t('Number of users to show in top users page.'),
    );
    $form['affiliate_module_settings']['configuration']['top_users']['affiliate_module_top_users_count_block'] = array(
      '#type' => 'select',
      '#title' => t('Top Users Count For Block'),
      '#default_value' => \Drupal::state()->get('affiliate_module_top_users_count_block', 5),
      '#options' => array(5 => 5, 10 => 10, 25 => 25, 50 => 50, 100 => 100),
      '#description' => t('Number of users to show in top users block.'),
    );
    $form['affiliate_module_settings']['configuration']['top_users']['affiliate_module_top_users_period_interval'] = array(
      '#type' => 'select',
      '#title' => t('Period for top users block and page'),
      '#default_value' => \Drupal::state()->get('affiliate_module_top_users_period_interval', 259200),
      '#options' => array_map('format_callback', array_combine(86400, 172800, 259200, 259200, 432000, 604800, 1209600, 2592000)),
      '#description' => t('How long of a timespan will be used as the limit for what is shown in the top users page?'),
    );

    return $form;

  }


  /**
   * Required by FormBase.
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {

  }

  /**
   * Required by FormBase.
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

  }

}
+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ uber_affiliate.affiliatemanagement.overview:
uber_affiliate.affiliatemanagement.users:
  path: 'admin/config/people/affiliate/users'
  defaults:
    _controller: 'Drupal\uber_affiliate\Controller\UberAffiliate::affiliate_admin_userspage'
    _form: 'Drupal\uber_affiliate\Form\UserConfigForm'
    _title: 'Users'
  requirements:
    _permission: 'administer affiliate settings'