You are here

public function BlazyAdminFormatterBase::imageStyleForm in Blazy 8

Same name and namespace in other branches
  1. 8.2 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()
BlazyAdminFormatter::buildSettingsForm in src/Form/BlazyAdminFormatter.php
Defines re-usable form elements.

File

src/Form/BlazyAdminFormatterBase.php, line 16

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. Not compatible with breakpoints and aspect ratio, yet. Leave empty to disable. <a href=":url" target="_blank">Manage responsive image styles</a>.', [
        ':url' => $url,
      ]),
      '#access' => $this
        ->getResponsiveImageOptions(),
      '#weight' => -100,
    ];
    if (!empty($definition['background'])) {
      $form['background']['#states'] = $this
        ->getState(static::STATE_RESPONSIVE_IMAGE_STYLE_DISABLED, $definition);
    }
  }
  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,
    ];
  }
}