You are here

public static function AdaptiveHeightModifier::modification in Modifiers Pack 8

File

modules/modifiers_adaptive_height/src/Plugin/modifiers/AdaptiveHeightModifier.php, line 22

Class

AdaptiveHeightModifier
Provides a Modifier to set the adaptive height on an element.

Namespace

Drupal\modifiers_adaptive_height\Plugin\modifiers

Code

public static function modification($selector, array $config) {
  if (!empty($config['ah_ratio'])) {
    $css = [];
    $media = parent::getMediaQuery($config);
    if (!empty($config['vertical_align'])) {
      $css[$media][$selector][] = 'display:flex';

      // Workaround for IE11.
      $css['all and (-ms-high-contrast:none),(-ms-high-contrast:active)'][$selector][] = 'height:1px';
      switch ($config['vertical_align']) {
        case 'top':
          $css[$media][$selector][] = 'align-items:flex-start';
          break;
        case 'middle':
          $css[$media][$selector][] = 'align-items:center';
          break;
        case 'bottom':
          $css[$media][$selector][] = 'align-items:flex-end';
          break;
      }
    }
    $libraries = [
      'modifiers_adaptive_height/apply',
    ];
    $settings = [
      'namespace' => 'AdaptiveHeightModifier',
      'callback' => 'apply',
      'selector' => $selector,
      'media' => $media,
      'args' => [
        'ratio' => (double) $config['ah_ratio'],
        'limit' => '1200',
        'comparison' => 'content_width',
      ],
    ];
    if (!empty($config['ah_limit'])) {
      $settings['args']['limit'] = (int) $config['ah_limit'];
    }
    if (!empty($config['ah_comparison'])) {
      $settings['args']['comparison'] = $config['ah_comparison'];
    }
    return new Modification($css, $libraries, $settings);
  }
  return NULL;
}