class YandexServicesAuthForm in Yandex Services Authorization API 8
Provides form for Yandex Services Authorization.
Hierarchy
- class \Drupal\yandex_services_auth\Form\YandexServicesAuthForm implements FormInterface
Expanded class hierarchy of YandexServicesAuthForm
1 string reference to 'YandexServicesAuthForm'
File
- lib/
Drupal/ yandex_services_auth/ Form/ YandexServicesAuthForm.php, line 15 - Contains \Drupal\yandex_metrics\Form\YandexMetricsCounterSettingsForm.
Namespace
Drupal\yandex_services_auth\FormView source
class YandexServicesAuthForm implements FormInterface {
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
*/
public function getFormID() {
return 'yandex_services_auth_form';
}
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
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;
}
/**
* Implements \Drupal\Core\Form\FormInterface::validateForm().
*/
public function validateForm(array &$form, array &$form_state) {
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$client_id = $form_state['values']['yandex_services_auth_client_id'];
\Drupal::state()
->set('yandex_services_auth_client_id', $form_state['values']['yandex_services_auth_client_id']);
\Drupal::state()
->set('yandex_services_auth_client_secret', $form_state['values']['yandex_services_auth_client_secret']);
$request_url = 'https://oauth.yandex.ru/authorize';
$params = array(
'response_type' => 'code',
'client_id' => $client_id,
);
$form_state['redirect'] = url($request_url, array(
'query' => $params,
'external' => TRUE,
));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormInterface:: |
public | function | Returns a unique string identifying the form. | 236 |
YandexServicesAuthForm:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::buildForm(). Overrides FormInterface:: |
|
YandexServicesAuthForm:: |
public | function | Implements \Drupal\Core\Form\FormInterface::getFormID(). | |
YandexServicesAuthForm:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::submitForm(). Overrides FormInterface:: |
|
YandexServicesAuthForm:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface:: |