public function AmazonFieldFormatter::settingsForm in Amazon Product Advertisement API 8.2
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form elements for the formatter settings.
Overrides FormatterBase::settingsForm
File
- modules/
amazon_field/ src/ Plugin/ Field/ FieldFormatter/ AmazonFieldFormatter.php, line 65
Class
- AmazonFieldFormatter
- Plugin implementation of the 'amazon_field_formatter' formatter.
Namespace
Drupal\amazon_field\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$defaultMaxAge = \Drupal::config('amazon.settings')
->get('default_max_age');
$form['max_age'] = [
'#type' => 'textfield',
'#title' => $this
->t('Max age for cached results'),
'#description' => $this
->t('The number of seconds that the system should cache the results from Amazon\'s servers. Leave blank to use the default max age set on the <a href=":url">Amazon settings page</a>, currently set at @default_max_age seconds.', [
':url' => Url::fromRoute('amazon.settings_form')
->toString(),
'@default_max_age' => $defaultMaxAge,
]),
'#default_value' => $this
->getSetting('max_age') == $defaultMaxAge ? '' : $this
->getSetting('max_age'),
];
$form['template'] = [
'#type' => 'select',
'#title' => $this
->t('Display item as'),
'#description' => $this
->t('By default, all options will link to the item in the Amazon store tagged with your Associates ID.'),
'#options' => $this->templateOptions,
'#default_value' => $this
->getSetting('template'),
];
$form['advanced'] = [
'#type' => 'details',
'#title' => $this
->t('Advanced options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$form['advanced']['extraResponseGroups'] = [
'#type' => 'textarea',
'#title' => $this
->t('Additional response groups'),
'#description' => $this
->t('Use this field to add additional <a href="@amazon_link">response groups</a> to the information supplied to templates. This is only needed if you are overwriting the Twig templates and want addition product information. One response group per line, response groups <em>Small</em> and <em>Images</em> are included by default.', [
'@amazon_link' => Url::fromUri('http://docs.aws.amazon.com/AWSECommerceService/latest/DG/CHAP_ResponseGroupsList.html'),
]),
'#default_value' => $this
->getSettings()['advanced']['extraResponseGroups'],
];
return $form + parent::settingsForm($form, $form_state);
}