You are here

public function GinLoginConfigurationForm::buildForm in Gin Login 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/GinLoginConfigurationForm.php, line 32

Class

GinLoginConfigurationForm
Class SettingsForm.

Namespace

Drupal\gin_login\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('gin_login.settings');
  $default_scheme = $this
    ->config('system.file')
    ->get('default_scheme');
  $form['logo'] = [
    '#type' => 'details',
    '#title' => t('Logo image'),
    '#open' => TRUE,
  ];
  $form['logo']['default_logo'] = [
    '#type' => 'checkbox',
    '#title' => t('Use default logo'),
    '#default_value' => $config
      ->get('logo.use_default'),
    '#tree' => FALSE,
  ];
  $form['logo']['settings'] = [
    '#type' => 'container',
    '#states' => [
      // Hide the logo settings when using the default logo.
      'invisible' => [
        'input[name="default_logo"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['logo']['settings']['logo_path'] = [
    '#type' => 'textfield',
    '#title' => t('Path to custom logo'),
    '#default_value' => $config
      ->get('logo.path') ? str_replace($default_scheme . '://', "", $config
      ->get('logo.path')) : '',
  ];
  $form['logo']['settings']['logo_upload'] = [
    '#type' => 'file',
    '#title' => t('Upload logo image'),
    '#maxlength' => 40,
    '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."),
    '#upload_validators' => [
      'file_validate_is_image' => [],
    ],
  ];
  $form['brand_image'] = [
    '#type' => 'details',
    '#title' => t('Brand image'),
    '#open' => TRUE,
  ];
  $form['brand_image']['default_brand_image'] = [
    '#type' => 'checkbox',
    '#title' => t('Use random image'),
    '#default_value' => $config
      ->get('brand_image.use_default'),
    '#tree' => FALSE,
  ];
  $form['brand_image']['settings'] = [
    '#type' => 'container',
    '#states' => [
      // Hide the logo settings when using the default logo.
      'invisible' => [
        'input[name="default_brand_image"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['brand_image']['settings']['brand_image_path'] = [
    '#type' => 'textfield',
    '#title' => t('Path to custom brand image'),
    '#default_value' => $config
      ->get('brand_image.path') ? str_replace($default_scheme . '://', "", $config
      ->get('brand_image.path')) : '',
  ];
  $form['brand_image']['settings']['brand_image_upload'] = [
    '#type' => 'file',
    '#title' => t('Upload Brand image'),
    '#maxlength' => 40,
    '#description' => t("If you don't have direct file access to the server, use this field to upload your brand image."),
    '#upload_validators' => [
      'file_validate_is_image' => [],
    ],
  ];
  return parent::buildForm($form, $form_state);
}