You are here

public function ImageStyleImageFormatter::settingsForm in Field Image Style 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/ImageStyleImageFormatter.php, line 37

Class

ImageStyleImageFormatter
Plugin implementation of the 'image_style_formatter' formatter.

Namespace

Drupal\field_image_style\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $options = array();

  // @todo: find a way to get all image_style fields of the current entity bundle
  $entityfieldmanager = \Drupal::service('entity_field.manager');
  $fields_image_style = $entityfieldmanager
    ->getFieldMapByFieldType('image_style');
  $fields_image_style = array_intersect_key($fields_image_style[$form['#entity_type']], array_flip($form['#fields']));
  foreach ($fields_image_style as $field_name => $info) {
    if (in_array($form['#bundle'], $info['bundles'])) {
      $options[$field_name] = $field_name;
    }
  }
  $element['field_image_style'] = array(
    '#title' => t('Field image style'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('field_image_style'),
    '#empty_option' => t('None (original image)'),
    '#options' => $options,
  );
  $link_types = array(
    'content' => t('Content'),
    'file' => t('File'),
  );
  $element['image_link'] = array(
    '#title' => t('Link image to'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('image_link'),
    '#empty_option' => t('Nothing'),
    '#options' => $link_types,
  );
  return $element;
}