public function SvgImageFieldFormatter::settingsForm in SVG Image Field 8
Same name and namespace in other branches
- 2.1.x src/Plugin/Field/FieldFormatter/SvgImageFieldFormatter.php \Drupal\svg_image_field\Plugin\Field\FieldFormatter\SvgImageFieldFormatter::settingsForm()
- 2.0.x src/Plugin/Field/FieldFormatter/SvgImageFieldFormatter.php \Drupal\svg_image_field\Plugin\Field\FieldFormatter\SvgImageFieldFormatter::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 FormatterBase::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ SvgImageFieldFormatter.php, line 65
Class
- SvgImageFieldFormatter
- Plugin implementation of the 'svg_formatter' formatter.
Namespace
Drupal\svg_image_field\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$form['inline'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Output SVG inline'),
'#default_value' => $this
->getSetting('inline'),
'#description' => $this
->t('Check this option if you want to manipulate the SVG image with CSS and JavaScript.
Notice only trusted users should use fields with this option enabled because of
<a href="@svg_security_link">inline svg security</a>', [
'@svg_security_link' => 'https://www.w3.org/wiki/SVG_Security',
]),
];
$form['apply_dimensions'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Apply dimensions.'),
'#default_value' => $this
->getSetting('apply_dimensions'),
];
$form['width'] = [
'#type' => 'number',
'#title' => $this
->t('Image width.'),
'#default_value' => $this
->getSetting('width'),
];
$form['height'] = [
'#type' => 'number',
'#title' => $this
->t('Image height.'),
'#default_value' => $this
->getSetting('height'),
];
$form['enable_alt'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable alt attribute.'),
'#default_value' => $this
->getSetting('enable_alt'),
];
$form['enable_title'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable title attribute.'),
'#default_value' => $this
->getSetting('enable_title'),
];
$form['notice'] = [
'#type' => 'markup',
'#markup' => '<div><small>' . $this
->t('Alt and title attributes will be created from an image filename by removing file extension and replacing eventual underscores and dashes with spaces.') . '</small></div>',
];
$form['link'] = [
'#title' => $this
->t('Link image to'),
'#type' => 'select',
'#default_value' => $this
->getSetting('link'),
'#empty_option' => $this
->t('Nothing'),
'#options' => $this
->getLinkTypes(),
];
return $form;
}