You are here

public function ConfigDefaultImageFormatter::settingsForm in Config default image 8

Overrides ImageFormatter::settingsForm

See also

\Drupal\image\Plugin\Field\FieldType\ImageItem

File

src/Plugin/Field/FieldFormatter/ConfigDefaultImageFormatter.php, line 107

Class

ConfigDefaultImageFormatter
Plugin implementation of the 'image' formatter.

Namespace

Drupal\config_default_image\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = parent::settingsForm($form, $form_state);
  $settings = $this
    ->getSettings();
  $element['default_image'] = [
    '#type' => 'details',
    '#title' => t('Default image'),
    '#open' => TRUE,
    '#required' => TRUE,
  ];
  $element['default_image']['path'] = [
    '#type' => 'textfield',
    '#title' => t('Image path'),
    '#description' => t('Drupal path to the image to be shown if no image is uploaded (the image would typically be in a git-managed directory so that it can be deployed easily). Example: /themes/custom/my_theme/img/default_image.jpg'),
    '#default_value' => $settings['default_image']['path'],
    '#required' => TRUE,
  ];
  $element['default_image']['use_image_style'] = [
    '#type' => 'checkbox',
    '#title' => t('Apply the image style'),
    '#description' => t('Check this box to use the image style on the default image'),
    '#default_value' => $settings['default_image']['use_image_style'],
  ];
  $element['default_image']['alt'] = [
    '#type' => 'textfield',
    '#title' => t('Alternative text'),
    '#description' => t('This text will be used by screen readers, search engines, and when the image cannot be loaded.'),
    '#default_value' => $settings['default_image']['alt'],
    '#maxlength' => 512,
  ];
  $element['default_image']['title'] = [
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#description' => t('The title attribute is used as a tooltip when the mouse hovers over the image.'),
    '#default_value' => $settings['default_image']['title'],
    '#maxlength' => 1024,
  ];
  $element['default_image']['width'] = [
    '#type' => 'value',
    '#value' => $settings['default_image']['width'],
  ];
  $element['default_image']['height'] = [
    '#type' => 'value',
    '#value' => $settings['default_image']['height'],
  ];
  $element['default_image']['#description'] = t('If no image is set for the field (not even a field-level default image), this image will be shown on display.');
  return $element;
}