cms_portfolio.module in Glazed CMS Portfolio 8
Same filename and directory in other branches
Primary module hooks for CMS Portfolio module.
File
cms_portfolio.moduleView source
<?php
/**
* @file
* Primary module hooks for CMS Portfolio module.
*/
/**
* Implements hook_theme().
*/
function cms_portfolio_theme() {
return [
'cms_portfolio_twentytwenty' => [
'variables' => [
'images' => NULL,
],
'template' => 'twentytwenty',
],
];
}
/**
* Implements hook_field_group_pre_render().
*/
function cms_portfolio_field_group_pre_render(&$element, $group, &$form) {
if ($group->bundle == 'cms_portfolio_project' && $group->context == 'view') {
$layout = 'top';
if (!empty($form['#node']
->get('field_cms_portfolio_layout')
->getString())) {
$layout = $form['#node']
->get('field_cms_portfolio_layout')
->getString();
}
elseif (theme_get_setting('portfolio_details')) {
$layout = theme_get_setting('portfolio_details');
}
$sidebar = 4;
if (!empty($form['#node']
->get('field_cms_portfolio_sb_width')
->getString())) {
$sidebar = $form['#node']
->get('field_cms_portfolio_sb_width')
->getString();
}
elseif (theme_get_setting('portfolio_sidebar')) {
$sidebar = theme_get_setting('portfolio_sidebar');
}
$main = 12 - $sidebar;
$sidebar_class = 'col-sm-' . $sidebar;
$main_class = 'col-sm-' . $main;
// LAYOUT CLASSES FOR PORTFOLIO NODES
// Top Fields Wrapper Field Group
if ($group->group_name == 'group_cms_portfolio_top_fields') {
// Set weight to change source order of groups
if ($layout == 'hide') {
unset($element['group_extra_fields']);
unset($element['field_cms_page_body']);
}
else {
if ($layout == 'right' or $layout == 'bottom') {
$group->weight = 99;
}
if ($layout == 'bottom' or $layout == 'top') {
$group->format_settings['classes'] .= ' row';
$element['field_cms_page_body']['#attributes'] = [
'class' => [
$main_class,
],
];
}
else {
$group->format_settings['classes'] .= ' ' . $sidebar_class;
}
}
}
// Extra Fields Field Group
if ($group->group_name == 'group_extra_fields') {
if ($layout == 'bottom' or $layout == 'top') {
$group->format_settings['classes'] .= ' ' . $sidebar_class;
}
else {
$element['#prefix'] = '<hr>';
}
}
// Images Field Group
if ($group->group_name == 'group_cms_portfolio_images') {
if ($layout == 'left' or $layout == 'right') {
$group->format_settings['classes'] .= ' ' . $main_class;
}
}
}
}
/**
* Implements template_preprocess_node()
*/
function cms_portfolio_preprocess_node(&$variables) {
if ($variables['node']
->bundle() == 'cms_portfolio_project' && $variables['view_mode'] == 'full') {
// Determine portoflio layout to see if we need to add a row class to content div
$layout = 'top';
if (!empty($layout = $variables['node']
->get('field_cms_portfolio_layout')
->getString())) {
$layout = $variables['node']
->get('field_cms_portfolio_layout')
->getString();
}
elseif (theme_get_setting('portfolio_details')) {
$layout = theme_get_setting('portfolio_details');
}
if ($layout == 'left' or $layout == 'right') {
$variables['content_attributes'] = [
'class' => [
'row',
],
];
}
$variables['attributes']['class'][] = 'node-details-' . $layout;
// Add classes for image display to node (sidecaption, lightbox, etc)
$style = 'sidecaption';
if (!empty($variables['node']
->get('field_cms_portfolio_image_style')
->getString())) {
$style = $variables['node']
->get('field_cms_portfolio_image_style')
->getString();
}
elseif (theme_get_setting('portfolio_images')) {
$style = theme_get_setting('portfolio_images');
}
$variables['attributes']['class'][] = 'node-images-' . $style;
if ($style == 'grid') {
$variables['#attached']['library'][] = 'glazed/ilightbox';
}
if ($style == 'hide') {
hide($variables['content']['field_cms_page_image']);
}
}
}
Functions
Name | Description |
---|---|
cms_portfolio_field_group_pre_render | Implements hook_field_group_pre_render(). |
cms_portfolio_preprocess_node | Implements template_preprocess_node() |
cms_portfolio_theme | Implements hook_theme(). |