You are here

public function SvgImageFormatter::settingsForm in Svg Image 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Field/FieldFormatter/SvgImageFormatter.php \Drupal\svg_image\Plugin\Field\FieldFormatter\SvgImageFormatter::settingsForm()
  2. 1.x src/Plugin/Field/FieldFormatter/SvgImageFormatter.php \Drupal\svg_image\Plugin\Field\FieldFormatter\SvgImageFormatter::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/SvgImageFormatter.php, line 193

Class

SvgImageFormatter
Plugin implementation of the 'image' formatter.

Namespace

Drupal\svg_image\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $element, FormStateInterface $formState) {
  $element = parent::settingsForm($element, $formState);
  $element['svg_render_as_image'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Render SVG image as <img>'),
    '#description' => $this
      ->t('Render SVG images as usual image in IMG tag instead of <svg> tag'),
    '#default_value' => $this
      ->getSetting('svg_render_as_image'),
  ];
  $element['svg_attributes'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('SVG Images dimensions (attributes)'),
    '#tree' => TRUE,
  ];
  $element['svg_attributes']['width'] = [
    '#type' => 'number',
    '#min' => 0,
    '#title' => $this
      ->t('Width'),
    '#size' => 10,
    '#field_suffix' => 'px',
    '#default_value' => $this
      ->getSetting('svg_attributes')['width'],
  ];
  $element['svg_attributes']['height'] = [
    '#type' => 'number',
    '#min' => 0,
    '#title' => $this
      ->t('Height'),
    '#size' => 10,
    '#field_suffix' => 'px',
    '#default_value' => $this
      ->getSetting('svg_attributes')['height'],
  ];
  return $element;
}