You are here

public function RocketChatSettingsForm::buildForm in Rocket.Chat 8

Same name and namespace in other branches
  1. 8.2 src/Form/RocketChatSettingsForm.php \Drupal\rocket_chat\Form\RocketChatSettingsForm::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/RocketChatSettingsForm.php, line 108
Contains \Drupal\rocket_chat\Form\RocketChatSettingsForm.

Class

RocketChatSettingsForm
Class RocketChatSettingsForm.

Namespace

Drupal\rocket_chat\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
  $config = $this
    ->config('rocket_chat.settings');
  $server = $config
    ->get('server');
  $form['url'] = [
    '#type' => 'url',
    '#title' => $this
      ->t('The Rocket.chat server address:'),
    '#required' => FALSE,
  ];

  // Only set the value if there is a value.
  if (!empty($server)) {
    $form['url']['#defaultvalue'] = $server;
    $form['url']['#attributes']['placeholder'] = $server;
  }
  else {
    $form['url']['#attributes']['placeholder'] = "https://demo.rocket.chat/";
  }

  // Only add the following when the rocket_chat_api module is enabled.
  if ($this->moduleHandler
    ->moduleExists('rocket_chat_api')) {
    $form['rocketchat_admin'] = [
      '#type' => 'password',
      '#description' => $this
        ->t("Rocket chat Admin login name (for API use)"),
      '#title' => $this
        ->t('Rocketchat Admin User:'),
      '#required' => FALSE,
      '#attributes' => [
        'placeholder' => empty($config
          ->get('user')) ? "<Rocket chat Admin user name>" : $config
          ->get('user'),
      ],
    ];
    $form['rocketchat_key'] = [
      '#type' => 'password',
      '#title' => $this
        ->t('Rocketchat Admin Password:'),
      '#description' => $this
        ->t("Rocket chat Admin login password (for API use)"),
      '#required' => FALSE,
      '#attributes' => [
        'placeholder' => '****************',
      ],
    ];
  }
  return parent::buildForm($form, $form_state);
}