You are here

public static function AbsoluteHeightModifier::modification in Modifiers Pack 8

1 call to AbsoluteHeightModifier::modification()
AbsoluteHeightModifierTest::testModification in modules/modifiers_absolute_height/tests/src/Unit/AbsoluteHeightModifierTest.php
@covers ::modification

File

modules/modifiers_absolute_height/src/Plugin/modifiers/AbsoluteHeightModifier.php, line 22

Class

AbsoluteHeightModifier
Provides a Modifier to set the absolute height on an element.

Namespace

Drupal\modifiers_absolute_height\Plugin\modifiers

Code

public static function modification($selector, array $config) {
  if (!empty($config['height'])) {
    $css = [];
    $libraries = [];
    $settings = [];
    $media = parent::getMediaQuery($config);
    $unit = 'px';
    if (!empty($config['vertical_align'])) {
      $css[$media][$selector][] = 'display:flex';
      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;
      }
    }
    if (!empty($config['height_units'])) {
      $unit = $config['height_units'];
    }
    if ($unit === '%') {
      $libraries = [
        'modifiers_absolute_height/apply',
      ];
      $settings = [
        'namespace' => 'AbsoluteHeightModifier',
        'callback' => 'apply',
        'selector' => $selector,
        'media' => $media,
        'args' => [
          'height' => $config['height'],
        ],
      ];
    }
    else {
      $css[$media][$selector][] = 'height:' . $config['height'] . $unit;
    }
    return new Modification($css, $libraries, $settings);
  }
  return NULL;
}