You are here

public function YandexServicesAuthForm::buildForm in Yandex Services Authorization API 8

Implements \Drupal\Core\Form\FormInterface::buildForm().

Overrides FormInterface::buildForm

File

lib/Drupal/yandex_services_auth/Form/YandexServicesAuthForm.php, line 27
Contains \Drupal\yandex_metrics\Form\YandexMetricsCounterSettingsForm.

Class

YandexServicesAuthForm
Provides form for Yandex Services Authorization.

Namespace

Drupal\yandex_services_auth\Form

Code

public function buildForm(array $form, array &$form_state, $action = NULL) {
  $auth_token = \Drupal::state()
    ->get('yandex_services_auth_token') ?: '';
  if (!empty($auth_token)) {
    $auth_status = '<span style="color:green;">' . t('The application is already authorized.') . '</span>';
  }
  else {
    $auth_status = '<span style="color:red;">' . t('The application is not authorized yet.') . '</span>';
  }
  $form['yandex_services_auth_text'] = array(
    '#type' => 'item',
    '#markup' => $auth_status,
  );
  $form['yandex_services_auth_client_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Client ID'),
    '#description' => t('Your application client ID.'),
    '#required' => TRUE,
    '#default_value' => \Drupal::state()
      ->get('yandex_services_auth_client_id') ?: '',
  );
  $form['yandex_services_auth_client_secret'] = array(
    '#type' => 'textfield',
    '#title' => t('Client Secret'),
    '#description' => t('Your application secret.'),
    '#default_value' => \Drupal::state()
      ->get('yandex_services_auth_client_secret') ?: '',
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => !empty($auth_token) ? t('Re-Authorize') : t('Authorize'),
  );
  return $form;
}