You are here

public function ImageEmbedDataFormatter::settingsForm in Formatter Suite 8

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/ImageEmbedDataFormatter.php, line 147

Class

ImageEmbedDataFormatter
Embeds an image as a data URL instead of a file URL.

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $formState) {

  // Start with the parent form.
  $elements = parent::settingsForm($form, $formState);

  // Add branding.
  $elements = Branding::addFieldFormatterBranding($elements);
  $elements['#attached']['library'][] = 'formatter_suite/formatter_suite.fieldformatter';

  // Add description.
  $elements['description'] = [
    '#type' => 'html_tag',
    '#tag' => 'div',
    '#value' => $this
      ->getDescription(),
    '#weight' => -1000,
    '#attributes' => [
      'class' => [
        'formatter_suite-settings-description',
      ],
    ],
  ];
  $weight = 100;

  // Prompt for each setting.
  $elements['sectionBreak'] = [
    '#markup' => '<div class="formatter_suite-section-break"></div>',
    '#weight' => $weight++,
  ];
  $elements['maximumEmbedWidth'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum width'),
    '#size' => 10,
    '#default_value' => $this
      ->getSetting('maximumEmbedWidth'),
    '#weight' => $weight++,
  ];
  $elements['maximumEmbedHeight'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum height'),
    '#size' => 10,
    '#default_value' => $this
      ->getSetting('maximumEmbedHeight'),
    '#description' => $this
      ->t("Images this size or smaller will be embedded, while larger images will be left as file URLs. If a maximum is empty or zero, that dimension has no maximum."),
    '#weight' => $weight++,
  ];
  return $elements;
}