drowl_paragraphs_bs-1.x-dev/modules/drowl_paragraphs_bs_type_attachments/drowl_paragraphs_bs_type_attachments.module
modules/drowl_paragraphs_bs_type_attachments/drowl_paragraphs_bs_type_attachments.module
<?php
/**
* @file
* Drowl_paragraphs_bs_type_attachments module.
*/
/**
* Implements hook_preprocess_paragraph().
*/
function drowl_paragraphs_bs_type_attachments_preprocess_paragraph(&$variables) {
// Implement attachement paragraph options.
if ($variables['paragraph']->bundle() === "attachments") {
$variables['#attached']['library'][] = 'drowl_paragraphs_bs_type_attachments/global';
if (isset($variables['attributes']['class'])) {
$button_classes = [];
foreach ($variables['attributes']['class'] as $class) {
if (str_starts_with($class, 'btn-')) {
$variables['attributes']->removeClass($class);
array_push($button_classes, $class);
}
}
// Pass to elements['#drowl_media'].button_classes so we can merge them
// into drowl_media/drowl_base media document templates.
foreach ($variables['content']['field_attachments']['#items'] as $key => $value) {
$variables['content']['field_attachments'][$key]['#drowl_media']['button_classes'] = $button_classes;
// @todo As we're operating on a referenced entities outout here, we should
// also clear the referenced enttity's render cache (by cache tag)
// on paragraph save, see https://www.drupal.org/project/drowl_paragraphs_bs/issues/3222165
// @todo @JP still required? not sure how this needs to be modified..
// $variables['content']['field_attachments'][$key]['#cache']['keys'][] = 'drowl_media:media_link_button_expanded';
}
}
}
}
/**
* Implements hook_theme().
*/
function drowl_paragraphs_bs_type_attachments_theme($existing, $type, $theme, $path) {
$templates = $path . '/templates';
return [
'paragraph__drowl_paragraphs_bs__attachments' => [
'base hook' => 'paragraph',
'path' => $templates,
],
];
}
