You are here

public function RestExampleClientSettings::buildForm in Examples for Developers 3.x

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

modules/rest_example/src/Form/RestExampleClientSettings.php, line 27

Class

RestExampleClientSettings
Setup form for a Drupal REST client.

Namespace

Drupal\rest_example\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['intro'] = [
    '#markup' => t('Set here the remote server options.'),
  ];
  $form['server_url'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Remote server URL'),
    '#description' => $this
      ->t('Format like this: http://www.example.com or http://www.example.com/test-site (no trailing slash)'),
    '#default_value' => $this
      ->config('rest_example.settings')
      ->get('server_url'),
    '#required' => TRUE,
  ];
  $form['server_username'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Remote server username'),
    '#default_value' => $this
      ->config('rest_example.settings')
      ->get('server_username'),
    '#description' => $this
      ->t('A user on the remote system that has the proper rights to use the REST service'),
    '#required' => TRUE,
  ];
  $form['server_password'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Remote server password'),
    '#default_value' => $this
      ->config('rest_example.settings')
      ->get('server_password'),
    '#description' => $this
      ->t('Remote users password'),
    '#required' => TRUE,
  ];
  return parent::buildForm($form, $form_state);
}