ColorBackgroundModifier.php in Modifiers Pack 8
File
modules/modifiers_color_background/src/Plugin/modifiers/ColorBackgroundModifier.php
View source
<?php
namespace Drupal\modifiers_color_background\Plugin\modifiers;
use Drupal\modifiers\Modification;
use Drupal\modifiers\ModifierPluginBase;
class ColorBackgroundModifier extends ModifierPluginBase {
public static function modification($selector, array $config) {
$attributes = [];
$media = parent::getMediaQuery($config);
if (!empty($config['bc_bg_color_val'])) {
$args['color'] = $config['bc_bg_color_val'];
$attributes[$media][$selector]['class'][] = 'modifiers-has-background';
}
if (!empty($config['bc_bg_h_color_val'])) {
$args['hover'] = $config['bc_bg_h_color_val'];
if (empty($config['bc_bg_color_val'])) {
$attributes[$media][$selector]['class'][] = 'modifiers-has-background';
}
}
if (!empty($config['transition_duration'])) {
$args['transition'] = $config['transition_duration'];
}
if (!empty($args)) {
$libraries = [
'modifiers_color_background/apply',
];
$settings = [
'namespace' => 'ColorBackgroundModifier',
'callback' => 'apply',
'selector' => $selector,
'media' => $media,
'args' => $args,
];
return new Modification([], $libraries, $settings, $attributes);
}
return NULL;
}
}