drowl_paragraphs_bs-1.x-dev/modules/drowl_paragraphs_bs_type_gallery/drowl_paragraphs_bs_type_gallery.module
modules/drowl_paragraphs_bs_type_gallery/drowl_paragraphs_bs_type_gallery.module
<?php
/**
* @file
* Drowl_paragraphs_bs_type_gallery module.
*/
use Drupal\Core\Template\Attribute;
/**
* Prepared variables for paragraph output.
*/
function drowl_paragraphs_bs_type_gallery_preprocess_paragraph(&$variables) {
if ($variables['paragraph']->bundle() == 'gallery') {
$variables['#attached']['library'][] = 'drowl_paragraphs_bs_type_gallery/global';
$variables['gallery_attributes'] = new Attribute();
$variables['image_wrapper_attributes'] = new Attribute();
if (isset($variables['attributes']['class'])) {
foreach ($variables['attributes']['class'] as $class) {
if (str_starts_with($class, 'gallery-grid--') || str_starts_with($class, 'gap-')) {
$variables['attributes']->removeClass($class);
$variables['gallery_attributes']->addClass($class);
}
elseif (str_starts_with($class, 'img-wrapper__')) {
$variables['attributes']->removeClass($class);
$variables['image_wrapper_attributes']->addClass(str_replace('img-wrapper__', '', $class));
}
elseif (str_starts_with($class, 'img-') || str_starts_with($class, 'ratio')) {
$variables['attributes']->removeClass($class);
$variables['image_wrapper_attributes']->addClass($class);
}
}
}
}
}
/**
* Implements hook_theme().
*/
function drowl_paragraphs_bs_type_gallery_theme($existing, $type, $theme, $path) {
$templates = $path . '/templates';
return [
'paragraph__drowl_paragraphs_bs__gallery' => [
'base hook' => 'paragraph',
'path' => $templates,
],
];
}
