You are here

public function GoogleApiClientForm::buildForm in Google API PHP Client 8.2

Same name and namespace in other branches
  1. 8.4 src/Form/GoogleApiClientForm.php \Drupal\google_api_client\Form\GoogleApiClientForm::buildForm()
  2. 8.3 src/Form/GoogleApiClientForm.php \Drupal\google_api_client\Form\GoogleApiClientForm::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 EntityForm::buildForm

File

src/Form/GoogleApiClientForm.php, line 18

Class

GoogleApiClientForm
Form controller for the google_api_client entity edit forms.

Namespace

Drupal\google_api_client\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  /* @var $entity \Drupal\google_api_client\Entity\GoogleApiClient */
  $form = parent::buildForm($form, $form_state);
  $form['scopes']['widget']['#prefix'] = '<div id="scopes-wrapper">';
  $form['scopes']['widget']['#suffix'] = '</div>';
  if ($form_state
    ->getValue('services')) {
    $services = [];
    foreach ($form_state
      ->getValue('services') as $values) {
      $services[] = $values['value'];
    }
    $scopes = google_api_client_google_services_scopes($services);
    $form['scopes']['widget']['#options'] = $scopes;
  }
  $form['#attached']['library'][] = 'google_api_client/google_api_client.add_client';
  $entity = $this->entity;
  return $form;
}