public function GoogleApiClientForm::buildForm in Google API PHP Client 8.4
Same name and namespace in other branches
- 8.2 src/Form/GoogleApiClientForm.php \Drupal\google_api_client\Form\GoogleApiClientForm::buildForm()
- 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 19
Class
- GoogleApiClientForm
- Form controller for the google_api_client entity edit forms.
Namespace
Drupal\google_api_client\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
if (!google_api_client_load_library()) {
// We don't have library installed notify admin and abort.
$status_report_link = Link::createFromRoute($this
->t('Status Report'), 'system.status')
->toString();
$this
->messenger()
->addError($this
->t('Google Api PHP Client library is not installed, please check %status_report for more details.', [
'%status_report' => $status_report_link,
]));
return $this
->redirect('entity.google_api_client.collection');
}
$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';
return $form;
}