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