You are here

public static function LinearGradientModifier::modification in Modifiers Pack 8

1 call to LinearGradientModifier::modification()
LinearGradientModifierTest::testModification in modules/modifiers_linear_gradient/tests/src/Unit/LinearGradientModifierTest.php
@covers ::modification

File

modules/modifiers_linear_gradient/src/Plugin/modifiers/LinearGradientModifier.php, line 22

Class

LinearGradientModifier
Provides a Modifier to set the linear gradient on an element.

Namespace

Drupal\modifiers_linear_gradient\Plugin\modifiers

Code

public static function modification($selector, array $config) {
  if (!empty($config['l_gradient_colors'])) {
    $media = parent::getMediaQuery($config);
    $direction = '';
    if (!empty($config['l_gradient_direction'])) {
      $direction = $config['l_gradient_direction'] . 'deg,';
    }

    // If there is only one color specified we use single color fill.
    if (count($config['l_gradient_colors']) === 1) {
      $css[$media][$selector][] = 'background:' . $config['l_gradient_colors'][0];
    }
    else {
      $css[$media][$selector][] = 'background:linear-gradient(' . $direction . implode(',', $config['l_gradient_colors']) . ')';
    }
    $attributes[$media][$selector]['class'][] = 'modifiers-has-background';
    return new Modification($css, [], [], $attributes);
  }
  return NULL;
}