You are here

class FormtipsSettingForm in Form Tips 8

Configure Form Tips settings for this site.

Hierarchy

Expanded class hierarchy of FormtipsSettingForm

1 string reference to 'FormtipsSettingForm'
formtips.routing.yml in ./formtips.routing.yml
formtips.routing.yml

File

src/Form/FormtipsSettingForm.php, line 14

Namespace

Drupal\formtips\Form
View source
class FormtipsSettingForm extends ConfigFormBase {

  /**
   * The theme handler.
   *
   * @var ThemeHandlerInterface
   */
  protected $themeHandler;

  /**
   * {@inheritdoc}
   */
  public function __construct(ConfigFactoryInterface $config_factory, ThemeHandlerInterface $theme_handler) {
    parent::__construct($config_factory);
    $this->themeHandler = $theme_handler;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'), $container
      ->get('theme_handler'));
  }

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

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this
      ->config('formtips.settings');
    $config_data = $config
      ->getRawData();
    foreach ($config_data as $key => $value) {
      $config
        ->set($key, $form_state
        ->getValue($key));
    }
    $config
      ->save();
    parent::submitForm($form, $form_state);
  }

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $formtips_settings = $this
      ->config('formtips.settings');
    $themes = [];

    /** @var \Drupal\Core\Extension\Extension $theme */
    foreach ($this->themeHandler
      ->listInfo() as $theme_key => $theme) {
      $themes[$theme_key] = $theme->info['name'];
    }
    $form['formtips_themes'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Themes'),
      '#description' => $this
        ->t('Select the themes for which formtips will be applied (selecting none will apply to all).'),
      '#options' => $themes,
      '#multiple' => TRUE,
      '#default_value' => $formtips_settings
        ->get('formtips_themes'),
    ];
    $form['formtips_trigger_action'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Trigger action'),
      '#description' => $this
        ->t('Select the action that will trigger the display of tooltips.'),
      '#options' => [
        'hover' => $this
          ->t('Hover'),
        'click' => $this
          ->t('Click'),
      ],
      '#default_value' => $formtips_settings
        ->get('formtips_trigger_action'),
    ];
    $form['formtips_selectors'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Selectors'),
      '#description' => $this
        ->t("Enter some CSS/XPATH selectors (jQuery compatible) for which you don't want to tigger formtips (one per line)."),
      '#default_value' => $formtips_settings
        ->get('formtips_selectors'),
    ];
    $form['formtips_max_width'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Max-width'),
      '#description' => $this
        ->t('Enter a value for the maximum width of the form description tooltip.'),
      '#default_value' => $formtips_settings
        ->get('formtips_max_width'),
    ];
    $form['intent'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Hover intent settings'),
      '#description' => $this
        ->t('Settings for controlling the hover intent plugin.'),
      '#states' => [
        'visible' => [
          ':input[name="formtips_trigger_action"]' => [
            'value' => 'hover',
          ],
        ],
      ],
    ];
    $form['intent']['formtips_hoverintent'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Add hoverIntent plugin'),
      '#description' => $this
        ->t('If the hoverIntent plugin is added by another module or in the theme you can switch this setting off.'),
      '#default_value' => $formtips_settings
        ->get('formtips_hoverintent'),
    ];
    $form['intent']['formtips_interval'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Interval'),
      '#description' => $this
        ->t('The number of milliseconds hoverIntent waits between reading/comparing mouse coordinates. When the user\'s mouse first enters the element its coordinates are recorded. The soonest the "over" function can be called is after a single polling interval. Setting the polling interval higher will increase the delay before the first possible "over" call, but also increases the time to the next point of comparison. Default interval: 100'),
      '#default_value' => $formtips_settings
        ->get('formtips_interval'),
    ];
    $form['intent']['formtips_sensitivity'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Sensitivity'),
      '#description' => $this
        ->t('If the mouse travels fewer than this number of pixels between polling intervals, then the "over" function will be called. With the minimum sensitivity threshold of 1, the mouse must not move between polling intervals. With higher sensitivity thresholds you are more likely to receive a false positive. Default sensitivity: 7'),
      '#default_value' => $formtips_settings
        ->get('formtips_sensitivity'),
    ];
    $form['intent']['formtips_timeout'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Timeout'),
      '#description' => $this
        ->t('A simple delay, in milliseconds, before the "out" function is called. If the user mouses back over the element before the timeout has expired the "out" function will not be called (nor will the "over" function be called). This is primarily to protect against sloppy/human mousing trajectories that temporarily (and unintentionally) take the user off of the target element... giving them time to return. Default timeout: 0'),
      '#default_value' => $formtips_settings
        ->get('formtips_timeout'),
    ];
    return parent::buildForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
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
FormtipsSettingForm::$themeHandler protected property The theme handler.
FormtipsSettingForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
FormtipsSettingForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
FormtipsSettingForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
FormtipsSettingForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
FormtipsSettingForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
FormtipsSettingForm::__construct public function Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase::__construct
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.