public function GoogleApiServiceClientForm::form in Google API PHP Client 8.4
Same name and namespace in other branches
- 8.3 src/Form/GoogleApiServiceClientForm.php \Drupal\google_api_client\Form\GoogleApiServiceClientForm::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/ GoogleApiServiceClientForm.php, line 40
Class
- GoogleApiServiceClientForm
- Form controller for the google_api_service_client entity edit forms.
Namespace
Drupal\google_api_client\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$google_api_service_client = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $google_api_service_client
->label(),
'#description' => $this
->t("Label for the Example."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $google_api_service_client
->id(),
'#machine_name' => [
'exists' => [
$this,
'exist',
],
],
'#disabled' => !$google_api_service_client
->isNew(),
];
$form['auth_config'] = [
'#type' => 'textarea',
'#title' => $this
->t('Credentials'),
'#default_value' => $google_api_service_client
->isNew() ? '' : Json::encode($google_api_service_client
->getAuthConfig()),
'#description' => $this
->t("Credential json file downloaded from google console."),
'#required' => TRUE,
'#placeholder' => $this
->t('Example: {
"type": "service_account",
"project_id": "SERVICEACCOUNT",
"private_key_id": "PRIVATE_KEY_ID",
"private_key": "-----BEGIN PRIVATE KEY-----\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ab\\nadaksdfaskdfjaskdf\\n-----END PRIVATE KEY-----\\n",
"client_email": "google-service-account@servicesaccount.iam.gserviceaccount.com",
"client_id": "CLIEND_ID",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/google-service-account%40servicesaccount.iam.gserviceaccount.com"
}'),
];
$services = _google_api_client_google_services_names();
$form['services'] = [
'#type' => 'select',
'#multiple' => TRUE,
'#title' => $this
->t('Services'),
'#default_value' => $google_api_service_client
->isNew() ? '' : $google_api_service_client
->getServices(),
'#options' => $services,
];
$services = array_keys($services);
$scopes = google_api_client_google_services_scopes($services);
$form['scopes'] = [
'#type' => 'select',
'#multiple' => TRUE,
'#title' => $this
->t('Scopes'),
'#default_value' => $google_api_service_client
->isNew() ? '' : $google_api_service_client
->getScopes(),
'#options' => $scopes,
];
$form['#attached']['library'][] = 'google_api_client/google_api_client.add_client';
// You will need additional form elements for your custom properties.
return $form;
}