You are here

public function RenameAdminPathsSettingsForm::buildForm in Rename Admin Paths 8

Same name and namespace in other branches
  1. 8.2 src/Form/RenameAdminPathsSettingsForm.php \Drupal\rename_admin_paths\Form\RenameAdminPathsSettingsForm::buildForm()

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/RenameAdminPathsSettingsForm.php, line 32

Class

RenameAdminPathsSettingsForm
Implements an example form.

Namespace

Drupal\rename_admin_paths\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('rename_admin_paths.settings');
  $callbacks = new RenameAdminPathsCallbacks();
  $form['admin_path'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Rename admin path'),
  ];
  $form['admin_path']['admin_path'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Rename admin path'),
    '#default_value' => $config
      ->get('admin_path'),
    '#description' => $this
      ->t('If checked, "admin" will be replaced by the following term in admin path.'),
  ];
  $form['admin_path']['admin_path_value'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Replace "admin" in admin path by'),
    '#default_value' => $config
      ->get('admin_path_value'),
    '#description' => $this
      ->t('This value will replace "admin" in admin path.'),
    '#element_validate' => [
      [
        $callbacks,
        'validatePath',
      ],
    ],
  ];
  $form['user_path'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Rename user path'),
  ];
  $form['user_path']['user_path'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Rename user path'),
    '#default_value' => $config
      ->get('user_path'),
    '#description' => $this
      ->t('If checked, "user" will be replaced by the following term in user path.'),
  ];
  $form['user_path']['user_path_value'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Replace "user" in user path by'),
    '#default_value' => $config
      ->get('user_path_value'),
    '#description' => $this
      ->t('This value will replace "user" in user path.'),
    '#element_validate' => [
      [
        $callbacks,
        'validatePath',
      ],
    ],
  ];
  return parent::buildForm($form, $form_state);
}