You are here

function cms_portfolio_preprocess_node in Glazed CMS Portfolio 8

Same name and namespace in other branches
  1. 7 cms_portfolio.module \cms_portfolio_preprocess_node()

Implements template_preprocess_node()

File

./cms_portfolio.module, line 84
Primary module hooks for CMS Portfolio module.

Code

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']);
    }
  }
}