You are here

public static function CustomRadialGradientModifier::modification in Modifiers Pack 8

1 call to CustomRadialGradientModifier::modification()
CustomRadialGradientModifierTest::testModification in modules/modifiers_custom_radial_gradient/tests/src/Unit/CustomRadialGradientModifierTest.php
@covers ::modification

File

modules/modifiers_custom_radial_gradient/src/Plugin/modifiers/CustomRadialGradientModifier.php, line 22

Class

CustomRadialGradientModifier
Provides a Modifier to set the radial gradient on an element.

Namespace

Drupal\modifiers_custom_radial_gradient\Plugin\modifiers

Code

public static function modification($selector, array $config) {
  if (!empty($config['cr_gradient_colors'])) {
    $media = parent::getMediaQuery($config);
    $args['colors'] = $config['cr_gradient_colors'];
    $args['shape'] = 'ellipse';
    $args['size'] = 'farthest-corner';
    $args['x'] = 50;
    $args['y'] = 50;
    if (!empty($config['cr_gradient_shape'])) {
      $args['shape'] = $config['cr_gradient_shape'];
    }
    if (!empty($config['cr_gradient_size'])) {
      $args['size'] = $config['cr_gradient_size'];
    }
    if (!empty($config['cr_gradient_position'][0])) {
      $args['x'] = (double) $config['cr_gradient_position'][0];
    }
    if (!empty($config['cr_gradient_position'][1])) {
      $args['y'] = (double) $config['cr_gradient_position'][1];
    }
    $libraries = [
      'modifiers_custom_radial_gradient/apply',
    ];
    $settings = [
      'namespace' => 'CustomRadialGradientModifier',
      'callback' => 'apply',
      'selector' => $selector,
      'media' => $media,
      'args' => $args,
    ];
    $attributes[$media][$selector]['class'][] = 'modifiers-has-background';
    return new Modification([], $libraries, $settings, $attributes);
  }
  return NULL;
}