You are here

public function AuthorizeForm::buildForm in OAuth2 Server 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/AuthorizeForm.php \Drupal\oauth2_server\Form\AuthorizeForm::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 FormInterface::buildForm

File

src/Form/AuthorizeForm.php, line 56

Class

AuthorizeForm
Class Authorize Form.

Namespace

Drupal\oauth2_server\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $context = []) {
  $form['#title'] = $this
    ->t('Authorize @client to use your account?', [
    '@client' => $context['client']
      ->label(),
  ]);
  $list = [];
  foreach ($context['scopes'] as $scope) {

    // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString
    $list[] = $this
      ->t($scope->description);
  }
  $form['client'] = [
    '#type' => 'value',
    '#value' => $context['client'],
  ];
  $form['scopes'] = [
    '#title' => $this
      ->t('This application will be able to:'),
    '#theme' => 'item_list',
    '#items' => $list,
    '#type' => 'ul',
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => t('Yes, I authorize this request.'),
    '#authorized' => TRUE,
  ];
  $form['actions']['cancel'] = [
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#authorized' => FALSE,
  ];
  return $form;
}