drowl_paragraphs_bs-1.x-dev/modules/drowl_paragraphs_bs_type_image/drowl_paragraphs_bs_type_image.module
modules/drowl_paragraphs_bs_type_image/drowl_paragraphs_bs_type_image.module
<?php
/**
* @file
* Drowl_paragraphs_bs_type_image module.
*/
use Drupal\Core\Template\Attribute;
/**
* Prepared variables for paragraph output.
*/
function drowl_paragraphs_bs_type_image_preprocess_paragraph(&$variables) {
if ($variables['paragraph']->bundle() == 'image' || $variables['paragraph']->bundle() == 'vector_image') {
// Get icon & icon combo specific ui_styles so we can apply them to
// this specific wrappers, instead the paragraph wrapper.
$variables['image_wrapper_attributes'] = new Attribute();
if (isset($variables['attributes']['class'])) {
foreach ($variables['attributes']['class'] as $class) {
if (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_image_theme($existing, $type, $theme, $path) {
$templates = $path . '/templates';
return [
'paragraph__drowl_paragraphs_bs__image' => [
'base hook' => 'paragraph',
'path' => $templates,
],
'paragraph__drowl_paragraphs_bs__vector_image' => [
'base hook' => 'paragraph',
'path' => $templates,
],
];
}
