You are here

public function ScopeForm::form in OAuth2 Server 8

Same name and namespace in other branches
  1. 2.0.x src/Form/ScopeForm.php \Drupal\oauth2_server\Form\ScopeForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/ScopeForm.php, line 56

Class

ScopeForm
Class Scope Form.

Namespace

Drupal\oauth2_server\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $scope = $this->entity;
  $server = $form_state
    ->get('oauth2_server');
  if (!$server) {
    throw new \Exception('OAuth2 server was not set');
  }
  $form['#tree'] = TRUE;
  $form['scope_id'] = [
    '#type' => 'machine_name',
    '#default_value' => !$scope
      ->isNew() ? $scope->scope_id : '',
    '#maxlength' => 50,
    '#required' => TRUE,
  ];
  $form['server_id'] = [
    '#type' => 'value',
    '#value' => $server
      ->id(),
  ];
  $form['description'] = [
    '#title' => $this
      ->t('Description'),
    '#type' => 'textfield',
    '#default_value' => $scope->description,
    '#description' => $this
      ->t('Used to describe the scope to the user on the authorization form.'),
    '#required' => TRUE,
  ];
  $form['default'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Default'),
    '#default_value' => $scope
      ->isDefault(),
  ];
  return parent::form($form, $form_state);
}