You are here

class CrazyeggSettingsForm in Crazy Egg Integration 8

Returns responses for Crazyegg module routes.

Hierarchy

Expanded class hierarchy of CrazyeggSettingsForm

1 string reference to 'CrazyeggSettingsForm'
crazyegg.routing.yml in ./crazyegg.routing.yml
crazyegg.routing.yml

File

src/Form/CrazyeggSettingsForm.php, line 18
Contains Drupal\crazyegg\Form\CrazyeggSettingsForm.

Namespace

Drupal\crazyegg\Form
View source
class CrazyeggSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'crazyegg_settings_form';
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this
      ->config('crazyegg.settings')
      ->set('crazyegg_enabled', $form_state
      ->getValue('crazyegg_enabled'))
      ->set('crazyegg_account_id', $form_state
      ->getValue('crazyegg_account_id'))
      ->set('crazyegg_js_scope', $form_state
      ->getValue('crazyegg_js_scope'))
      ->set('crazyegg_roles_excluded', $form_state
      ->getValue('crazyegg_roles_excluded'))
      ->set('crazyegg_paths', $form_state
      ->getValue('crazyegg_paths'))
      ->save();
    if (method_exists($this, '_submitForm')) {
      $this
        ->_submitForm($form, $form_state);
    }
    parent::submitForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'crazyegg.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
    $form = [];
    $form['crazyegg_heading'] = array(
      '#type' => 'item',
      '#markup' => $this
        ->t('<img src="@logo" style="float: right;" alt="Crazy Egg">' . '<a href="@url">Crazy Egg</a> is an analytics tool that provides website heatmaps and eye tracking.<br/><br/>', array(
        '@url' => 'https://www.crazyegg.com',
        '@logo' => 'https://ceblog.s3.amazonaws.com/wp-content/uploads/2015/06/Crazy-Egg-logo-small.png',
      )),
    );
    $form['crazyegg_enabled'] = array(
      '#type' => 'radios',
      '#title' => $this
        ->t('Crazy Egg Enabled?'),
      '#default_value' => \Drupal::config('crazyegg.settings')
        ->get('crazyegg_enabled'),
      '#options' => array(
        1 => $this
          ->t('Yes'),
        -1 => $this
          ->t('No'),
      ),
    );
    $form['crazyegg_account_id'] = array(
      '#type' => 'textfield',
      '#title' => $this
        ->t('Crazy Egg Account ID'),
      '#attributes' => array(
        'placeholder' => $this
          ->t('e.g. 00111111'),
      ),
      '#default_value' => \Drupal::config('crazyegg.settings')
        ->get('crazyegg_account_id'),
      '#description' => $this
        ->t('This is your numerical CrazyEgg account ID, it is 8 digits long.<br/>' . 'The easiest way to find it is by logging in to your CrazyEgg account.<br/>' . 'Click on Account. Under your profile and email address, you’ll see your account number.'),
    );
    $form['advanced_settings'] = array(
      '#type' => 'details',
      '#title' => $this
        ->t('More settings'),
      '#open' => FALSE,
    );
    $form['advanced_settings']['crazyegg_js_scope'] = array(
      '#type' => 'radios',
      '#title' => $this
        ->t('Location to add the tracking script'),
      '#description' => $this
        ->t('Controls where on the page the tracking script is added'),
      '#default_value' => \Drupal::config('crazyegg.settings')
        ->get('crazyegg_js_scope'),
      '#options' => array(
        'header' => $this
          ->t('Header <em>(recommended)</em>'),
        'footer' => $this
          ->t('Footer'),
      ),
    );
    $form['advanced_settings']['crazyegg_roles_excluded'] = array(
      '#type' => 'checkboxes',
      '#options' => user_role_names(),
      '#title' => $this
        ->t('Excluded roles (optional)'),
      '#default_value' => \Drupal::config('crazyegg.settings')
        ->get('crazyegg_roles_excluded'),
      '#description' => $this
        ->t('You can control which visits and clicks are tracked in Crazy Egg by excluding roles.<br/>' . 'For example, if you have traffic generated by employees, it’s difficult to distinguish visits ' . 'from your visitors versus those visits from your own employees.<br/>' . 'To prevent internal traffic (i.e. administrators) from diluting your data, select "Administrator."'),
    );
    $form['advanced_settings']['crazyegg_paths'] = array(
      '#type' => 'textarea',
      '#title' => $this
        ->t('Pages to track (optional)'),
      '#default_value' => \Drupal::config('crazyegg.settings')
        ->get('crazyegg_paths'),
      '#description' => $this
        ->t('By default, Crazy Egg will track all pages within your domain.<br/>' . 'Need to track specific pages instead of all pages? You can specify which pages you\'d like to track ' . 'by providing the path (everything after .com). Include one path per line. For example,' . '<pre>  /home/about<br/>  /posts<br/>  /posts/*<br/>  /users/*/details</pre>'),
      '#cols' => 100,
      '#rows' => 5,
      '#resizable' => FALSE,
      '#required' => FALSE,
      '#weight' => 40,
    );
    $form['crazyegg_help'] = array(
      '#type' => 'item',
      '#markup' => $this
        ->t('<em>Note: if you don\'t get the desired effect after changing some settings, try clearing Drupal cache.</em><br/><br/>' . '<strong>Support:</strong> <a href="mailto:support@crazyegg.com">support@crazyegg.com</a><br />' . '<strong>Website: </strong><a href="https://www.crazyegg.com" target="_blank">https://www.crazyegg.com</a>'),
    );
    return parent::buildForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
CrazyeggSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
CrazyeggSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
CrazyeggSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
CrazyeggSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.