You are here

public function BlazyAdminBase::breakpointElements in Blazy 7

Same name and namespace in other branches
  1. 8 src/Form/BlazyAdminBase.php \Drupal\blazy\Form\BlazyAdminBase::breakpointElements()

Defines re-usable breakpoints form.

1 call to BlazyAdminBase::breakpointElements()
BlazyAdminBase::breakpointsForm in src/Form/BlazyAdminBase.php
Defines re-usable breakpoints form.

File

src/Form/BlazyAdminBase.php, line 219

Class

BlazyAdminBase
A base for blazy admin integration to have re-usable methods in one place.

Namespace

Drupal\blazy\Form

Code

public function breakpointElements($definition = []) {
  foreach ($definition['breakpoints'] as $breakpoint) {
    $form[$breakpoint]['breakpoint'] = [
      '#type' => 'item',
      '#markup' => $breakpoint,
      '#weight' => 1,
    ];

    // Regular #empty_option is not working with rendered.
    $form[$breakpoint]['image_style'] = [
      '#type' => 'select',
      '#title' => t('Image style'),
      '#title_display' => 'invisible',
      '#options' => [
        '' => t('- None -'),
      ] + image_style_options(FALSE),
      '#weight' => 2,
    ];
    $form[$breakpoint]['width'] = [
      '#type' => 'textfield',
      '#title' => t('Width'),
      '#title_display' => 'invisible',
      '#description' => t('See <strong>XS</strong> for detailed info.'),
      '#maz_length' => 32,
      '#size' => 6,
      '#weight' => 3,
      '#attributes' => [
        'class' => [
          'form-text--width',
        ],
      ],
    ];
    if ($breakpoint == 'xs') {
      $form[$breakpoint]['width']['#description'] = t('E.g.: <strong>640</strong>, or <strong>2x</strong>, or for <strong>small devices</strong> may be combined into <strong>640w 2x</strong> where <strong>x (pixel density)</strong> descriptor is used to define the device-pixel ratio, and <strong>w (width)</strong> descriptor is the width of image source and works in tandem with <strong>sizes</strong> attributes. Use <strong>w (width)</strong> if any issue/ unsure. Default to <strong>w</strong> if no descriptor provided for backward compatibility.');
    }
  }
  return $form;
}