You are here

public function ImageSizesFormatter::settingsForm in Picture 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 FormatterBase::settingsForm

File

src/Plugin/Field/FieldFormatter/ImageSizesFormatter.php, line 44
Contains \Drupal\picture\Plugin\field\formatter\ImageSizesFormatter.

Class

ImageSizesFormatter
Plugin for image with sizes attribute formatter.

Namespace

Drupal\picture\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements['sizes'] = array(
    '#title' => $this
      ->t('Sizes'),
    '#type' => 'textfield',
    '#description' => $this
      ->t('The value of the sizes attribute. See !link for more information.', array(
      '!link' => l($this
        ->t('the spec'), 'http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content.html#introduction-3:viewport-based-selection-2'),
    )),
    '#default_value' => $this
      ->getSetting('sizes'),
    '#required' => TRUE,
  );
  $image_styles = image_style_options(FALSE);
  $image_styles[RESPONSIVE_IMAGE_EMPTY_IMAGE] = $this
    ->t('- empty image -');
  $elements['image_styles'] = array(
    '#title' => t('Image styles'),
    '#type' => 'checkboxes',
    '#default_value' => $this
      ->getSetting('image_styles'),
    '#options' => $image_styles,
    '#required' => TRUE,
  );
  $elements['fallback_image_style'] = array(
    '#title' => t('Fallback image style'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('image_styles'),
    '#options' => $image_styles,
    '#required' => TRUE,
  );
  $link_types = array(
    'content' => t('Content'),
    'file' => t('File'),
  );
  $elements['image_link'] = array(
    '#title' => t('Link image to'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('image_link'),
    '#empty_option' => t('Nothing'),
    '#options' => $link_types,
  );
  return $elements;
}