You are here

class RelativeHeightModifier in Modifiers Pack 8

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

Plugin annotation


@Modifier(
  id = "relative_height_modifier",
  label = @Translation("Relative Height Modifier"),
  description = @Translation("Provides a Modifier to set the relative height on an element."),
)

Hierarchy

  • class \Drupal\modifiers_relative_height\Plugin\modifiers\RelativeHeightModifier extends \Drupal\modifiers\ModifierPluginBase

Expanded class hierarchy of RelativeHeightModifier

1 file declares its use of RelativeHeightModifier
RelativeHeightModifierTest.php in modules/modifiers_relative_height/tests/src/Unit/RelativeHeightModifierTest.php
2 string references to 'RelativeHeightModifier'
RelativeHeightModifier::modification in modules/modifiers_relative_height/src/Plugin/modifiers/RelativeHeightModifier.php
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 17

Namespace

Drupal\modifiers_relative_height\Plugin\modifiers
View source
class RelativeHeightModifier extends ModifierPluginBase {

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members