public function AmpImageFormatter::settingsForm in Accelerated Mobile Pages (AMP) 8
Same name and namespace in other branches
- 8.3 src/Plugin/Field/FieldFormatter/AmpImageFormatter.php \Drupal\amp\Plugin\Field\FieldFormatter\AmpImageFormatter::settingsForm()
- 8.2 src/Plugin/Field/FieldFormatter/AmpImageFormatter.php \Drupal\amp\Plugin\Field\FieldFormatter\AmpImageFormatter::settingsForm()
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 ImageFormatter::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ AmpImageFormatter.php, line 41 - Contains \Drupal\amp\Plugin\Field\FieldFormatter\AmpImageFormatter.
Class
- AmpImageFormatter
- Plugin implementation of the 'amp_image' formatter.
Namespace
Drupal\amp\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$layout_url = 'https://www.ampproject.org/docs/guides/responsive/control_layout.html#size-and-position-elements';
// Add configuration options for layout.
$element['amp_layout'] = [
'#title' => t('AMP Layout'),
'#type' => 'select',
'#default_value' => $this
->getSetting('amp_layout'),
'#empty_option' => t('None (no layout)'),
'#options' => $this
->getLayouts(),
'#description' => $this
->t('<a href=":url" target="_blank">Layout Information</a>', array(
':url' => $layout_url,
)),
];
// This information should only appear when 'fixed-height' is selected.
// TODO: figure out why amp_layout_height always shows.
$element['amp_fixed_height'] = array(
'#type' => 'textfield',
'#title' => t('Layout Height (used for fixed-height only)'),
'#states' => array(
'visible' => array(
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][amp_layout]"]' => array(
'value' => 'fixed-height',
),
),
),
'#size' => 10,
'#default_value' => $this
->getSetting('amp_fixed_height'),
);
return $element;
}