You are here

public function ImageUrlFormatter::settingsForm in Image URL Formatter 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/ImageUrlFormatter.php, line 112

Class

ImageUrlFormatter
Plugin implementation of the 'image_url' formatter.

Namespace

Drupal\image_url_formatter\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element['url_type'] = [
    '#title' => $this
      ->t('URL type'),
    '#type' => 'select',
    '#options' => [
      0 => $this
        ->t('Full URL'),
      1 => $this
        ->t('Absolute file path'),
      2 => $this
        ->t('Relative file path'),
    ],
    '#default_value' => $this
      ->getSetting('url_type'),
  ];

  //$element['url_type'][0]['#description'] = $this->t("Like: 'http://example.com/sites/default/files/image.png'");

  //$element['url_type'][1]['#description'] = $this->t("With leading slash, no base URL, like: '/sites/default/files/image.png'");

  //$element['url_type'][2]['#description'] = $this->t("No base URL or leading slash, like: 'sites/default/files/image.png'");
  $image_styles = image_style_options(FALSE);
  $element['image_style'] = [
    '#title' => $this
      ->t('Image style'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('image_style'),
    '#empty_option' => $this
      ->t('None (original image)'),
    '#options' => $image_styles,
    '#description' => [
      '#markup' => $this->linkGenerator
        ->generate($this
        ->t('Configure Image Styles'), new Url('entity.image_style.collection')),
      '#access' => $this->currentUser
        ->hasPermission('administer image styles'),
    ],
  ];
  $link_types = [
    'content' => $this
      ->t('Content'),
    'file' => $this
      ->t('File'),
  ];
  $element['image_link'] = [
    '#title' => $this
      ->t('Link image to'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('image_link'),
    '#empty_option' => $this
      ->t('Nothing'),
    '#options' => $link_types,
  ];
  return $element;
}