/**
* Implements hook_theme_suggestions_layout_alter().
*/
function varbase_layout_builder_theme_suggestions_layout_alter(array &$suggestions, array $variables) {
if (isset($variables['content'])
&& isset($variables['content']['#settings'])
&& isset($variables['content']['#settings']['vlb_section_config']) ) {
$suggestions[] = $variables['theme_hook_original'] . '__vlb';
}
}
/**
* Implements hook_theme().
*/
function varbase_layout_builder_theme($existing, $type, $theme, $path) {
$templates = $path . '/templates';
$theme_templates = [];
$theme_templates['bs_1col__vlb'] = [
'template' => 'bs-1col--vlb',
'path' => $templates,
'base hook' => 'layout',
'preprocess functions' => ['_bootstrap_layouts_preprocess_layout'],
];
$theme_templates['bs_2col__vlb'] = [
'template' => 'bs-2col--vlb',
'path' => $templates,
'base hook' => 'layout',
'preprocess functions' => ['_bootstrap_layouts_preprocess_layout'],
];
$theme_templates['bs_3col__vlb'] = [
'template' => 'bs-3col--vlb',
'path' => $templates,
'base hook' => 'layout',
'preprocess functions' => ['_bootstrap_layouts_preprocess_layout'],
];
$theme_templates['bs_4col__vlb'] = [
'template' => 'bs-4col--vlb',
'path' => $templates,
'base hook' => 'layout',
'preprocess functions' => ['_bootstrap_layouts_preprocess_layout'],
];
$theme_templates['media_oembed_iframe__remote_video__background_media'] = [
'template' => 'media-oembed-iframe--remote-video--background-media',
'variables' => [
'provider' => NULL,
'media' => NULL,
],
];
$theme_templates['media__image__background_media'] = [
'template' => 'media--image--background-media',
];
$theme_templates['media__video__background_media'] = [
'template' => 'media--video--background-media',
];
$theme_templates['media__remote_video__background_media'] = [
'template' => 'media--remote-video--background-media',
];
return $theme_templates;
}
/**
* Implements hook_preprocess_HOOK().
*/
function varbase_layout_builder_preprocess_media__video__background_media(&$variables) {
if (isset($variables['elements']['#view_mode'])
&& $variables['elements']['#view_mode'] == 'background_media') {
$background_media_video_fid = $variables['elements']['#media']->getSource()->getSourceFieldValue($variables['elements']['#media']);
$background_media_video_file = File::load($background_media_video_fid);
$variables['background_media_video_url'] = file_create_url($background_media_video_file->getFileUri());
$variables['background_media_video_type'] = $background_media_video_file->getMimeType();
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function varbase_layout_builder_preprocess_media__remote_video__background_media(&$variables) {
if (isset($variables['elements']['#view_mode'])
&& $variables['elements']['#view_mode'] === 'background_media') {
// When the view mode for the video is "Background Media" display mode.
// Add the bg class to the class attribute.
// And add the no to the scrolling attribute.
$variables['elements']['field_media_oembed_video'][0]['#attributes']['class'][] = 'bg';
$variables['elements']['field_media_oembed_video'][0]['#attributes']['scrolling'] = 'no';
}
}
/**
* Implements hook_preprocess_responsive_image().
*/
function varbase_layout_builder_preprocess_responsive_image(&$variables) {
if (isset($variables['responsive_image_style_id'])
&& $variables['responsive_image_style_id'] === 'de2e'
&& isset($variables['img_element'])) {
// Only for the de2e id
// When the Responsive image style is Display Edge-to-Edge responsive auto
// Add the bg class to the class attribute.
$variables['img_element']['#attributes']['class'][] = 'bg';
}
}
Comments
Comment #2
rajab natshahComment #4
rajab natshahComment #5
rajab natshahComment #6
rajab natshahComment #7
rajab natshah