You are here

class CustomLinearGradientModifier in Modifiers Pack 8

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

Plugin annotation


@Modifier(
  id = "custom_linear_gradient_modifier",
  label = @Translation("Custom Linear Gradient Modifier"),
  description = @Translation("Provides a Modifier to set the linear gradient on an element using custom colors."),
)

Hierarchy

Expanded class hierarchy of CustomLinearGradientModifier

1 file declares its use of CustomLinearGradientModifier
CustomLinearGradientModifierTest.php in modules/modifiers_custom_linear_gradient/tests/src/Unit/CustomLinearGradientModifierTest.php
1 string reference to 'CustomLinearGradientModifier'
CustomLinearGradientModifier::modification in modules/modifiers_custom_linear_gradient/src/Plugin/modifiers/CustomLinearGradientModifier.php

File

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

Namespace

Drupal\modifiers_custom_linear_gradient\Plugin\modifiers
View source
class CustomLinearGradientModifier extends ModifierPluginBase {

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

}

Members