You are here

public static function RelativeHeightModifier::modification in Modifiers Pack 8

1 call to RelativeHeightModifier::modification()
RelativeHeightModifierTest::testModification in modules/modifiers_relative_height/tests/src/Unit/RelativeHeightModifierTest.php
@covers ::modification

File

modules/modifiers_relative_height/src/Plugin/modifiers/RelativeHeightModifier.php, line 22

Class

RelativeHeightModifier
Provides a Modifier to set the relative height on an element.

Namespace

Drupal\modifiers_relative_height\Plugin\modifiers

Code

public static function modification($selector, array $config) {
  if (!empty($config['relative_height'])) {
    $media = parent::getMediaQuery($config);
    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;
      }
    }
    $libraries = [
      'modifiers_relative_height/apply',
    ];
    $settings = [
      'namespace' => 'RelativeHeightModifier',
      'callback' => 'apply',
      'selector' => $selector,
      'media' => $media,
      'args' => [
        'ratio' => $config['relative_height'],
      ],
    ];
    $css[$media][$selector][] = 'overflow:hidden';
    return new Modification($css, $libraries, $settings);
  }
  return NULL;
}