You are here

public function LockrLoginForm::buildForm in Lockr 8.2

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 FormInterface::buildForm

File

src/Form/LockrLoginForm.php, line 59
Contains Drupal\lockr\Form\LockrLoginForm.

Class

LockrLoginForm

Namespace

Drupal\lockr\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $site_client = $this->clientFactory
    ->getSiteClient();
  try {
    $status = $site_client
      ->exists();
  } catch (LockrServerException $e) {
    watchdog_exception('lockr', $e);
    drupal_set_message('The Lockr service has returned an error. Please try again.', 'error');
    return $form;
  }
  $exists = $status['exists'];
  if ($exists) {
    $form['registered'] = [
      '#title' => $this
        ->t("You're already registered"),
      '#prefix' => '<p>',
      '#markup' => $this
        ->t("This site is already registered with the Lockr Key Management Service. There's nothing left for you do to here, your keys entered in the key settings are already protected. If you registered with the wrong account, you can click <a href=\"https://lockr.io/user/login\" target=\"_blank\">here</a> to go to Lockr and manage your sites."),
      '#suffix' => '</p>',
    ];
    return $form;
  }
  $default_email = $this->requests
    ->getCurrentRequest()
    ->get('email');
  $form['email'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Email'),
    '#required' => TRUE,
    '#default_value' => $default_email,
    '#description' => $this
      ->t('Enter your Lockr email.'),
  ];
  $form['pass'] = [
    '#type' => 'password',
    '#title' => $this
      ->t('Password'),
    '#required' => TRUE,
    '#description' => $this
      ->t('Enter the password that accompanies your email.'),
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Log in'),
  ];
  return $form;
}