You are here

public static function CustomLinearGradientModifier::modification in Modifiers Pack 8

1 call to CustomLinearGradientModifier::modification()
CustomLinearGradientModifierTest::testModification in modules/modifiers_custom_linear_gradient/tests/src/Unit/CustomLinearGradientModifierTest.php
@covers ::modification

File

modules/modifiers_custom_linear_gradient/src/Plugin/modifiers/CustomLinearGradientModifier.php, line 22

Class

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

Namespace

Drupal\modifiers_custom_linear_gradient\Plugin\modifiers

Code

public static function modification($selector, array $config) {
  if (!empty($config['cl_gradient_direction'])) {
    $media = parent::getMediaQuery($config);
    $args['direction'] = (double) $config['cl_gradient_direction'];
    $args['colors'] = [];
    if (!empty($config['cl_gradient_colors'])) {
      $args['colors'] = $config['cl_gradient_colors'];
    }
    $libraries = [
      'modifiers_custom_linear_gradient/apply',
    ];
    $settings = [
      'namespace' => 'CustomLinearGradientModifier',
      'callback' => 'apply',
      'selector' => $selector,
      'media' => $media,
      'args' => $args,
    ];
    $attributes[$media][$selector]['class'][] = 'modifiers-has-background';
    return new Modification([], $libraries, $settings, $attributes);
  }
  return NULL;
}