You are here

function better_login_form_config_form_alter in Better Login Form Configuration 8

Same name and namespace in other branches
  1. 8.2 better_login_form_config.module \better_login_form_config_form_alter()

File

better_login_form_config/better_login_form_config.module, line 9

Code

function better_login_form_config_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  global $base_url;
  $myConfig = \Drupal::config('fancy_login.settings');
  $site_name = \Drupal::config('system.site')
    ->get('name');
  if ($form_id == 'user_login_form') {
    $myConfig = \Drupal::config('fancy_login.settings');

    // at the top of the method
    $form['name']['#title'] = !empty($myConfig
      ->get('username_label')) ? $myConfig
      ->get('username_label') : 'Username';
    $form['name']['#description'] = !empty($myConfig
      ->get('username_description')) ? $myConfig
      ->get('username_description') : t('Enter your @s username.', array(
      '@s' => $site_name,
    ));
    $form['pass']['#title'] = !empty($myConfig
      ->get('password_label')) ? $myConfig
      ->get('password_label') : 'Password';
    $form['pass']['#description'] = !empty($myConfig
      ->get('password_description')) ? $myConfig
      ->get('password_description') : 'Enter the password that accompanies your username.';
    if ($myConfig
      ->get('form_title')) {
      $request = \Drupal::request();
      if ($route = $request->attributes
        ->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
        $route
          ->setDefault('_title', $myConfig
          ->get('form_title'));
      }
    }
    $form['actions']['submit']['#value'] = !empty($myConfig
      ->get('login_button')) ? $myConfig
      ->get('login_button') : 'Log in';
  }
  if ($form_id == 'user_login_form' || $form_id == 'user_register_form' || $form_id == 'user_pass') {
    $form['#attached']['library'][] = 'better_login_form_config/fancylogin_css';
  }
  if ($form_id == 'user_register_form') {
    $form['name']['#title'] = !empty($myConfig
      ->get('forgot_form_username')) ? $myConfig
      ->get('forgot_form_username') : 'Username';
  }
  if ($form_id == 'user_register_form') {
    $form['account']['mail']['#description'] = !empty($myConfig
      ->get('register_mail_desc')) ? $myConfig
      ->get('register_mail_desc') : 'A valid email address. All emails from the system will be sent to this address. The email address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by email.';
    $form['account']['mail']['#title'] = !empty($myConfig
      ->get('register_form_mail')) ? $myConfig
      ->get('register_form_mail') : 'Email Address.';
    $form['account']['name']['#description'] = !empty($myConfig
      ->get('register_mail_desc')) ? $myConfig
      ->get('register_mail_desc') : "Several special characters are allowed, including space, period (.), hyphen (-), apostrophe ('), underscore (_), and the @ sign.";
    $form['account']['name']['#title'] = !empty($myConfig
      ->get('register_form_name')) ? $myConfig
      ->get('register_form_name') : 'Username';
    $form['actions']['submit']['#value'] = !empty($myConfig
      ->get('register_form_button')) ? $myConfig
      ->get('register_form_button') : 'Create new account.';
  }
}