You are here

public function BlazyAdminFormatterBase::imageStyleForm in Blazy 7

Same name and namespace in other branches
  1. 8.2 src/Form/BlazyAdminFormatterBase.php \Drupal\blazy\Form\BlazyAdminFormatterBase::imageStyleForm()
  2. 8 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 13

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_picture = function_exists('picture_get_mapping_options');
  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 (!empty($definition['responsive_image']) && $this
    ->manager()
    ->config('responsive_image', FALSE, 'blazy.settings')) {
    $responsive_options = $this
      ->getResponsiveImageOptions();
    $description = t('Not compatible with below breakpoints, aspect ratio, yet. However the image can be replaced by Picture if <strong>Picture</strong> option enabled at Blazy UI. Lazyload is taken care of by Picture, not Blazy. Leave empty to disable.');
    if ($is_picture && empty($responsive_options)) {
      $description = t('<a href="@url" target="_blank">No picture mappings</a> defined.', [
        '@url' => url('admin/config/media/picture'),
      ]);
    }
    $form['responsive_image_style'] = [
      '#type' => 'select',
      '#title' => t('Picture'),
      '#options' => $responsive_options,
      '#description' => $description,
      '#access' => $is_picture,
      '#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' => t('Thumbnail effect'),
      '#options' => isset($definition['thumbnail_effect']) ? $definition['thumbnail_effect'] : [],
      '#weight' => -100,
    ];
  }
}