You are here

public function SvgResponsiveImageFormatter::settingsForm in Svg Image 1.x

Same name and namespace in other branches
  1. 8 modules/svg_image_responsive/src/Plugin/Field/FieldFormatter/SvgResponsiveImageFormatter.php \Drupal\svg_image_responsive\Plugin\Field\FieldFormatter\SvgResponsiveImageFormatter::settingsForm()
  2. 2.x modules/svg_image_responsive/src/Plugin/Field/FieldFormatter/SvgResponsiveImageFormatter.php \Drupal\svg_image_responsive\Plugin\Field\FieldFormatter\SvgResponsiveImageFormatter::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 ResponsiveImageFormatter::settingsForm

File

modules/svg_image_responsive/src/Plugin/Field/FieldFormatter/SvgResponsiveImageFormatter.php, line 200

Class

SvgResponsiveImageFormatter
Plugin implementation of the 'responsive_image' formatter.

Namespace

Drupal\svg_image_responsive\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;
}