You are here

class FancyLoginSettingsForm in Fancy Login 8.2

Same name and namespace in other branches
  1. 3.0.x src/Form/FancyLoginSettingsForm.php \Drupal\fancy_login\Form\FancyLoginSettingsForm

Creates the settings form for the fancy login module.

Hierarchy

Expanded class hierarchy of FancyLoginSettingsForm

1 string reference to 'FancyLoginSettingsForm'
fancy_login.routing.yml in ./fancy_login.routing.yml
fancy_login.routing.yml

File

src/Form/FancyLoginSettingsForm.php, line 11

Namespace

Drupal\fancy_login\Form
View source
class FancyLoginSettingsForm extends ConfigFormBase {

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

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('fancy_login.settings');
    $form['display'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Display'),
      '#open' => FALSE,
    ];
    $form['display']['explanation'] = [
      '#value' => '<p>' . $this
        ->t('All settings on this page must be valid CSS settings for the item that they will modify. For information on what types of values are valid, check the links included in the descriptions underneath the inputs.') . '</p>',
    ];
    $form['display']['screen_fade_color'] = [
      '#title' => $this
        ->t('Screen Fade Color'),
      '#type' => 'textfield',
      '#maxlength' => 7,
      '#size' => 8,
      '#default_value' => $config
        ->get('screen_fade_color'),
      '#description' => $this
        ->t('This is the color that the screen fades to when the login box is activated. This should generally be black, white, or the same color as the background of your site. CSS property: <a href="@url.">background-color</a>', [
        '@url' => 'http://www.devguru.com/technologies/css2/8047',
      ]),
    ];
    $form['display']['screen_fade_z_index'] = [
      '#title' => $this
        ->t('Screen Fade z-index'),
      '#type' => 'textfield',
      '#maxlength' => 4,
      '#size' => 8,
      '#default_value' => $config
        ->get('screen_fade_z_index'),
      '#description' => $this
        ->t('This is the z-index of the faded screen. If you find elements on your layout are appearing over top of the faded out part of your screen, you can increase this number, but you should probably not touch it otherwise. CSS propery <a href="@url">z-index</a>.', [
        '@url' => 'http://www.devguru.com/technologies/css2/8139',
      ]),
    ];
    $form['display']['login_box_background_color'] = [
      '#title' => $this
        ->t('Login Box Background Color'),
      '#type' => 'textfield',
      '#maxlength' => 7,
      '#size' => 8,
      '#default_value' => $config
        ->get('login_box_background_color'),
      '#description' => $this
        ->t('This is the background color of the login box. CSS property: <a href="@url">background-color</a>.', [
        '@url' => 'http://www.devguru.com/technologies/css2/8047',
      ]),
    ];
    $form['display']['login_box_text_color'] = [
      '#title' => $this
        ->t('Login Box Text Color'),
      '#type' => 'textfield',
      '#maxlength' => 7,
      '#size' => 8,
      '#default_value' => $config
        ->get('login_box_text_color'),
      '#description' => $this
        ->t('This is the color of the text inside the login box. CSS property: <a href="@url">color</a>.', [
        '@url' => 'http://www.devguru.com/technologies/css2/8077',
      ]),
    ];
    $form['display']['login_box_border_color'] = [
      '#title' => $this
        ->t('Login Box Border Color'),
      '#type' => 'textfield',
      '#maxlength' => 7,
      '#size' => 8,
      '#default_value' => $config
        ->get('login_box_border_color'),
      '#description' => $this
        ->t('This is the color of the border around the login box. CSS property: <a href="@url">border-color</a>.', [
        '@url' => 'http://www.devguru.com/technologies/css2/8057',
      ]),
    ];
    $form['display']['login_box_border_width'] = [
      '#title' => $this
        ->t('Login Box Border Width'),
      '#type' => 'textfield',
      '#maxlength' => 7,
      '#size' => 8,
      '#default_value' => $config
        ->get('login_box_border_width'),
      '#description' => $this
        ->t('This is the width of the border around the login box. CSS property: <a href="@url">border-width</a>.', [
        '@url' => 'http://www.devguru.com/technologies/css2/8072',
      ]),
    ];
    $form['display']['login_box_border_style'] = [
      '#title' => $this
        ->t('Login Box Border Style'),
      '#type' => 'textfield',
      '#maxlength' => 7,
      '#size' => 8,
      '#default_value' => $config
        ->get('login_box_border_style'),
      '#description' => $this
        ->t('This is the style (eg: solid, dotted) of the border around the login box. CSS property: <a href="@url">border-style</a>.', [
        '@url' => 'http://www.devguru.com/technologies/css2/8067',
      ]),
    ];
    $form['display']['hide_objects'] = [
      '#title' => $this
        ->t('Hide Objects'),
      '#type' => 'checkbox',
      '#default_value' => $config
        ->get('hide_objects'),
      '#description' => $this
        ->t('If you are having issues where the fancy login box is being hidden behind videos or other flash objects, check this box to hide the objects while the login box is being shown'),
    ];
    $form['display']['dim_fade_time'] = [
      '#title' => $this
        ->t('Background Fade Time'),
      '#type' => 'textfield',
      '#default_value' => $config
        ->get('dim_fade_time'),
      '#maxlength' => 4,
      '#size' => 8,
      '#description' => $this
        ->t('This is the number of milliseconds it will take for the fullscreen background color to fade in/out. The higher the number, the slower the fade process will be. The lower the number, the faster the fade.'),
    ];
    $form['display']['login_box_fade_time'] = [
      '#title' => $this
        ->t('Login Box Fade Time'),
      '#type' => 'textfield',
      '#default_value' => $config
        ->get('login_box_fade_time'),
      '#maxlength' => 4,
      '#size' => 8,
      '#description' => $this
        ->t('This is the number of milliseconds it will take for the login box to fade in/out. The higher the number, the slower the fade process will be. The lower the number, the faster the fade.'),
    ];
    $form['no_redirect'] = [
      '#title' => $this
        ->t('Keep User on Same Page'),
      '#type' => 'checkbox',
      '#description' => $this
        ->t('If this box is checked, the user will not be redirected upon login, and will stay on the page from which the login link was clicked. If this box is unchecked, the user will be redirected according to the Drupal system settings'),
      '#default_value' => $config
        ->get('no_redirect'),
    ];
    $form['ssl'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('SSL (Secure Login)'),
      '#open' => FALSE,
    ];
    $form['ssl']['https'] = [
      '#title' => $this
        ->t('Enable SSL (HTTPS)'),
      '#type' => 'checkbox',
      '#description' => $this
        ->t('If this box is checked, the form will be posted as encrypted data (HTTPS/SSL). Only use this if you have already set up an SSL certificate on your site, and have set up the login page as an encrypted page.'),
      '#default_value' => $config
        ->get('https'),
    ];
    $form['ssl']['icon_position'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Secure login icon position'),
      '#options' => [
        $this
          ->t("Don't show icon"),
        $this
          ->t('Above the form'),
        $this
          ->t('Below the form'),
      ],
      '#default_value' => $config
        ->get('icon_position'),
      '#description' => $this
        ->t("If SSL is turned on, turning this option on will display an icon indicating that the login is secure"),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    $test_values = [
      'screen_fade_color',
      'screen_fade_z_index',
      'login_box_background_color',
      'login_box_text_color',
      'login_box_border_color',
      'login_box_border_width',
      'login_box_border_style',
    ];
    foreach ($test_values as $machine_name) {
      if (!strlen($form_state
        ->getValue($machine_name))) {
        $form_state
          ->setError($form[$machine_name], $this
          ->t('@field must contain a value', [
          '@field' => $form[$machien_name]['#title'],
        ]));
      }
    }
    if (!is_numeric(trim($form_state
      ->getValue('dim_fade_time')))) {
      $form_state
        ->setError($form['display']['dim_fade_time'], $this
        ->t('Background Fade Speed must contain a numeric value'));
    }
    if (!is_numeric(trim($form_state
      ->getValue('login_box_fade_time')))) {
      $form_state
        ->setError($form['display']['login_box_fade_time'], $this
        ->t('Login Box Fade Speed must contain a numeric value'));
    }
    parent::validateForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this
      ->config('fancy_login.settings')
      ->set('screen_fade_color', $form_state
      ->getValue('screen_fade_color'))
      ->set('screen_fade_z_index', $form_state
      ->getValue('screen_fade_z_index'))
      ->set('login_box_background_color', $form_state
      ->getValue('login_box_background_color'))
      ->set('login_box_text_color', $form_state
      ->getValue('login_box_text_color'))
      ->set('login_box_border_color', $form_state
      ->getValue('login_box_border_color'))
      ->set('login_box_border_width', $form_state
      ->getValue('login_box_border_width'))
      ->set('login_box_border_style', $form_state
      ->getValue('login_box_border_style'))
      ->set('hide_objects', $form_state
      ->getValue('hide_objects'))
      ->set('dim_fade_time', $form_state
      ->getValue('dim_fade_time'))
      ->set('login_box_fade_time', $form_state
      ->getValue('login_box_fade_time'))
      ->set('no_redirect', $form_state
      ->getValue('no_redirect'))
      ->set('https', $form_state
      ->getValue('https'))
      ->set('icon_position', $form_state
      ->getValue('icon_position'))
      ->save();
    parent::submitForm($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.
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
FancyLoginSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
FancyLoginSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
FancyLoginSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
FancyLoginSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
FancyLoginSettingsForm::validateForm public function Form validation handler. Overrides FormBase::validateForm
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.
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.