public function AdminSettings::buildForm in HubSpot 8
Same name and namespace in other branches
- 3.x src/Form/AdminSettings.php \Drupal\hubspot\Form\AdminSettings::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 ConfigFormBase::buildForm
File
- src/
Form/ AdminSettings.php, line 76
Class
- AdminSettings
- Hubspot admin settings form.
Namespace
Drupal\hubspot\FormCode
public function buildForm(array $form, FormStateInterface $form_state) : array {
$config = $this
->config(static::SETTINGS);
$form = [];
$form['settings'] = [
'#title' => $this
->t('Settings'),
'#type' => 'fieldset',
];
// Settings Tab.
$form['settings']['hubspot_portal_id'] = [
'#title' => $this
->t('HubSpot Portal ID'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => $config
->get('hubspot_portal_id'),
'#description' => $this
->t('Enter the HubSpot Portal ID for this site. <a href=":url" target="_blank">How do I find my portal ID?</a>.', [
'@url' => 'https://knowledge.hubspot.com/articles/kcs_article/account/where-can-i-find-my-hub-id',
]),
];
if ($config
->get('hubspot_portal_id')) {
$form['settings']['hubspot_authentication'] = [
'#value' => $this
->t('Connect HubSpot Account'),
'#type' => 'submit',
'#submit' => [
[
$this,
'hubspotOauthSubmitForm',
],
],
];
if ($this->state
->get('hubspot.hubspot_refresh_token')) {
$form['settings']['hubspot_authentication']['#suffix'] = $this
->t('Your HubSpot account is connected.');
$form['settings']['hubspot_authentication']['#value'] = $this
->t('Disconnect HubSpot Account');
$form['settings']['hubspot_authentication']['#submit'] = [
[
$this,
'hubspotOauthDisconnect',
],
];
}
}
// Application Settings.
$form['settings']['app_settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('App Settings'),
];
$form['settings']['app_settings']['hubspot_client_id'] = [
'#title' => $this
->t('HubSpot Client ID'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => $config
->get('hubspot_client_id'),
'#description' => $this
->t('Enter the HubSpot application Client ID.
<a href="https://developers.hubspot.com/docs/faq/how-do-i-create-an-app-in-hubspot" target="_blank">How do I find my Client ID?</a>'),
];
$form['settings']['app_settings']['hubspot_client_secret'] = [
'#title' => $this
->t('HubSpot Client Secret'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => $config
->get('hubspot_client_secret'),
'#description' => $this
->t('Enter the HubSpot application Client Secret.
<a href="https://developers.hubspot.com/docs/faq/how-do-i-create-an-app-in-hubspot" target="_blank">How do I find my Client Secret?</a>'),
];
$form['settings']['app_settings']['hubspot_scope'] = [
'#title' => $this
->t('HubSpot Scope'),
'#type' => 'textfield',
'#default_value' => $config
->get('hubspot_scope'),
'#description' => $this
->t('Enter the scopes required by your app. Click
<a href="https://developers.hubspot.com/docs/methods/oauth2/initiate-oauth-integration#scopes" target="_blank">here</a>
to see how to see what scopes are available and how to format them. For example, <em>contacts forms</em> will give you
access to the contacts and forms API on HubSpot. Note: Your HubSpot App, must have these options checked.'),
];
// Tracking Settings.
$form['settings']['tracking'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Tracking'),
];
$form['settings']['tracking']['tracking_code_on'] = [
'#title' => $this
->t('Enable Tracking Code'),
'#type' => 'checkbox',
'#default_value' => $config
->get('tracking_code_on'),
'#description' => $this
->t('If Tracking code is enabled, Javascript
tracking will be inserted in all/specified pages of the site as configured
in HubSpot account.'),
];
// Debug Settings.
$form['settings']['debugging'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Debugging'),
];
$form['settings']['debugging']['hubspot_debug_on'] = [
'#title' => $this
->t('Debugging enabled'),
'#type' => 'checkbox',
'#default_value' => $config
->get('hubspot_debug_on'),
'#description' => $this
->t('If debugging is enabled, HubSpot errors will be emailed to the address below. Otherwise, they
will be logged to the regular Drupal error log.'),
];
$form['settings']['debugging']['hubspot_debug_email'] = [
'#title' => $this
->t('Debugging email'),
'#type' => 'email',
'#default_value' => $config
->get('hubspot_debug_email'),
'#description' => $this
->t('Email error reports to this address if debugging is enabled.'),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Save Configuration',
];
return $form;
}