You are here

public function BlazyAdminFormatterBase::imageStyleForm in Blazy 8.2

Same name and namespace in other branches
  1. 8 src/Form/BlazyAdminFormatterBase.php \Drupal\blazy\Form\BlazyAdminFormatterBase::imageStyleForm()
  2. 7 src/Form/BlazyAdminFormatterBase.php \Drupal\blazy\Form\BlazyAdminFormatterBase::imageStyleForm()

Returns re-usable image formatter form elements.

1 call to BlazyAdminFormatterBase::imageStyleForm()
BlazyAdminFormatterBase::basicImageForm in src/Form/BlazyAdminFormatterBase.php
Defines re-usable basic form elements.

File

src/Form/BlazyAdminFormatterBase.php, line 40

Class

BlazyAdminFormatterBase
A base for field formatter admin to have re-usable methods in one place.

Namespace

Drupal\blazy\Form

Code

public function imageStyleForm(array &$form, $definition = []) {
  $is_responsive = function_exists('responsive_image_get_image_dimensions');
  if (empty($definition['no_image_style'])) {
    $form['image_style'] = $this
      ->baseForm($definition)['image_style'];
  }
  if (!empty($definition['thumbnail_style'])) {
    $form['thumbnail_style'] = $this
      ->baseForm($definition)['thumbnail_style'];
  }
  if ($is_responsive && !empty($definition['responsive_image'])) {
    $url = Url::fromRoute('entity.responsive_image_style.collection')
      ->toString();
    $form['responsive_image_style'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Responsive image'),
      '#options' => $this
        ->getResponsiveImageOptions(),
      '#description' => $this
        ->t('Responsive image style for the main stage image is more reasonable for large images. Works with multi-serving IMG, or PICTURE element. Leave empty to disable. <a href=":url" target="_blank">Manage responsive image styles</a>.', [
        ':url' => $url,
      ]),
      '#access' => $this
        ->getResponsiveImageOptions(),
      '#weight' => -100,
    ];
  }
  if (!empty($definition['thumbnail_effect'])) {
    $form['thumbnail_effect'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Thumbnail effect'),
      '#options' => isset($definition['thumbnail_effect']) ? $definition['thumbnail_effect'] : [],
      '#weight' => -100,
    ];
  }
}