public function AmpSettingsForm::buildForm in Accelerated Mobile Pages (AMP) 8
Same name and namespace in other branches
- 8.3 src/Form/AmpSettingsForm.php \Drupal\amp\Form\AmpSettingsForm::buildForm()
- 8.2 src/Form/AmpSettingsForm.php \Drupal\amp\Form\AmpSettingsForm::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/ AmpSettingsForm.php, line 122
Class
- AmpSettingsForm
- Defines the configuration export form.
Namespace
Drupal\amp\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$amp_config = $this
->config('amp.settings');
if (\Drupal::moduleHandler()
->moduleExists('field_ui')) {
$form['amp_content_amp_status'] = [
'#title' => $this
->t('AMP Status by Content Type'),
'#theme' => 'item_list',
'#items' => $this->entityTypeInfo
->getFormattedAmpEnabledTypes(),
];
}
else {
$form['amp_content_amp_status'] = [
'#type' => 'item',
'#title' => $this
->t('AMP Status by Content Type'),
'#markup' => $this
->t('(In order to enable and disable AMP content types in the UI, the Field UI module must be enabled.)'),
];
}
$amptheme_config = $this
->config('amp.theme');
$form['amptheme'] = [
'#type' => 'select',
'#options' => $this->themeOptions,
'#required' => TRUE,
'#title' => $this
->t('AMP theme'),
'#description' => $this
->t('Choose a theme to use for AMP pages.'),
'#default_value' => $amptheme_config
->get('amptheme'),
];
if (empty($this->themeOptions)) {
$form['amptheme']['#description'] = $this
->t('To use the AMP module, the AMP Base theme must be installed. You must choose between AMP Base or an installed subtheme of AMP Base, such as the ExAMPle Subtheme, for use as the AMP Theme in order to provide custom styles on AMP pages.');
}
$form['google_analytics_id'] = [
'#type' => 'textfield',
'#default_value' => $amp_config
->get('google_analytics_id'),
'#title' => $this
->t('Google Analytics Web Property ID'),
'#description' => $this
->t('This ID is unique to each site you want to track separately, and is in the form of UA-xxxxxxx-yy. To get a Web Property ID, <a href=":analytics">register your site with Google Analytics</a>, or if you already have registered your site, go to your Google Analytics Settings page to see the ID next to every site profile. <a href=":webpropertyid">Find more information in the documentation</a>.', [
':analytics' => 'http://www.google.com/analytics/',
':webpropertyid' => Url::fromUri('https://developers.google.com/analytics/resources/concepts/gaConceptsAccounts', [
'fragment' => 'webProperty',
])
->toString(),
]),
'#maxlength' => 20,
'#size' => 15,
'#placeholder' => 'UA-',
];
$form['google_adsense_id'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Google AdSense Publisher ID'),
'#default_value' => $amp_config
->get('google_adsense_id'),
'#maxlength' => 25,
'#size' => 20,
'#placeholder' => 'pub-',
'#description' => $this
->t('This is the Google AdSense Publisher ID for the site owner. Get this in your Google Adsense account. It should be similar to pub-9999999999999'),
);
$form['google_doubleclick_id'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Google DoubleClick for Publishers Network ID'),
'#default_value' => $amp_config
->get('google_doubleclick_id'),
'#maxlength' => 25,
'#size' => 20,
'#placeholder' => '/',
'#description' => $this
->t('The Network ID to use on all tags. This value should begin with a /.'),
);
$form['pixel_group'] = array(
'#type' => 'fieldset',
'#title' => t('amp-pixel'),
);
$form['pixel_group']['amp_pixel'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Enable amp-pixel'),
'#default_value' => $amp_config
->get('amp_pixel'),
'#description' => $this
->t('The amp-pixel element is meant to be used as a typical tracking pixel -- to count page views. Find more information in the <a href="https://www.ampproject.org/docs/reference/amp-pixel.html">amp-pixel documentation</a>.'),
);
$form['pixel_group']['amp_pixel_domain_name'] = array(
'#type' => 'textfield',
'#title' => $this
->t('amp-pixel domain name'),
'#default_value' => $amp_config
->get('amp_pixel_domain_name'),
'#description' => $this
->t('The domain name where the tracking pixel will be loaded: do not include http or https.'),
'#states' => array(
'visible' => array(
':input[name="amp_pixel"]' => array(
'checked' => TRUE,
),
),
),
);
$form['pixel_group']['amp_pixel_query_string'] = array(
'#type' => 'textfield',
'#title' => $this
->t('amp-pixel query path'),
'#default_value' => $amp_config
->get('amp_pixel_query_string'),
'#description' => $this
->t('The path at the domain where the GET request will be received, e.g. "pixel" in example.com/pixel?RANDOM.'),
'#states' => array(
'visible' => array(
':input[name="amp_pixel"]' => array(
'checked' => TRUE,
),
),
),
);
$form['pixel_group']['amp_pixel_random_number'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Random number'),
'#default_value' => $amp_config
->get('amp_pixel_random_number'),
'#description' => $this
->t('Use the special string RANDOM to add a random number to the URL if required. Find more information in the <a href="https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md#random">amp-pixel documentation</a>.'),
'#states' => array(
'visible' => array(
':input[name="amp_pixel"]' => array(
'checked' => TRUE,
),
),
),
);
$form['amp_library_group'] = array(
'#type' => 'fieldset',
'#title' => t('AMP Library Configuration <a href="https://github.com/Lullabot/amp-library">(GitHub Home and Documentation)</a>'),
);
$form['amp_library_group']['test_page'] = array(
'#type' => 'item',
'#markup' => t('<a href=":url">Test that AMP is configured properly</a>', array(
':url' => Url::fromRoute('amp.test_library_hello')
->toString(),
)),
);
$form['amp_library_group']['amp_library_warnings_display'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('<em>Debugging</em>: Show AMP Library warnings in <em>all</em> AMP text formatters for <em>all</em> users'),
'#default_value' => $amp_config
->get('amp_library_warnings_display'),
'#description' => $this
->t('If you only want to see AMP formatter specific warning for one node add query ' . '"warnfix=1" at end of a node url. e.g. <strong>node/12345?amp&warnfix=1</strong>'),
);
$form['amp_library_group']['amp_library_process_full_html'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('<strong><em>Power User:</em> Run the whole HTML page through the AMP library</strong>'),
'#default_value' => $amp_config
->get('amp_library_process_full_html'),
'#description' => $this
->t('The AMP PHP library will fix many AMP HTML standard non-compliance issues by ' . 'removing illegal or disallowed attributes, tags and property value pairs. This is useful for processing the output of modules that ' . 'generate AMP unfriendly HTML. Please test when enabling on your site as some modules may depend on ' . 'the HTML removed by the library and thus break in possibly subtle ways.'),
);
$form['amp_library_group']['amp_library_process_statistics'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('<em>Statistics:</em> Add an <a href="https://www.drupal.org/files/issues/time_taken.png">HTML comment</a> at the end of Drupal page output indicating various performance statistics like time taken, number of tags processed etc.'),
'#default_value' => $amp_config
->get('amp_library_process_statistics'),
'#states' => array(
'visible' => array(
':input[name="amp_library_process_full_html"]' => array(
'checked' => TRUE,
),
),
),
);
$form['amp_library_group']['amp_library_process_full_html_warnings'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('<em>Debugging:</em> Add a notice in the drupal log for each processed AMP page showing the AMP warnings (and fixes) generated'),
'#default_value' => $amp_config
->get('amp_library_process_full_html_warnings'),
'#description' => $this
->t('A Drupal log entry will be generated for <em>each</em> non-anonymous AMP request. ' . 'However <em>anonymous</em> page requests will be cached by Drupal page_cache module and will not repeatedly call the AMP library.'),
'#states' => array(
'visible' => array(
':input[name="amp_library_process_full_html"]' => array(
'checked' => TRUE,
),
),
),
);
return parent::buildForm($form, $form_state);
}