You are here

public function RealnameAdminSettingsForm::buildForm in Real Name 8

Same name and namespace in other branches
  1. 2.x src/Form/RealnameAdminSettingsForm.php \Drupal\realname\Form\RealnameAdminSettingsForm::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/RealnameAdminSettingsForm.php, line 30

Class

RealnameAdminSettingsForm
Configure Realname settings for this site.

Namespace

Drupal\realname\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('realname.settings');
  $form['general'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('General settings'),
  ];
  $note = '<div>';
  $note .= $this
    ->t('Note that if it is changed, all current Realnames will be deleted and the list in the database will be rebuilt as needed.');
  $note .= '</div>';
  $form['general']['realname_pattern'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Realname pattern'),
    '#default_value' => $config
      ->get('pattern'),
    '#element_validate' => [
      'token_element_validate',
    ],
    '#token_types' => [
      'user',
    ],
    '#min_tokens' => 1,
    '#required' => TRUE,
    '#maxlength' => 256,
    '#description' => $this
      ->t('This pattern will be used to construct Realnames for all users.') . $note,
  ];

  // Add the token tree UI.
  $form['general']['token_help'] = [
    '#theme' => 'token_tree_link',
    '#token_types' => [
      'user',
    ],
    '#global_types' => FALSE,
  ];
  return parent::buildForm($form, $form_state);
}