function oa_appearance_get_space_banner in Open Atrium Appearance 7.2
Get the banner settings for a particular Space.
Takes the parent Spaces and inheritence into account. Resulting values will be cached until the Space or any of it's parents are updated.
Parameters
integer $space_id: The NID of the Space.
integer $banner_position: The banner position to get settings for. Can be either:
Return value
array An associative array of the banner settings:
- position (string): Constant representing the banner position.
- image (array): Image field item representing the banner image.
- text (string): The banner text.
1 call to oa_appearance_get_space_banner()
- oa_space_banner_render in plugins/
content_types/ oa_space_banner.inc - Render callback for the panel.
File
- ./
oa_appearance.module, line 344 - Provides integration between Open Atrium and Colorizer module
Code
function oa_appearance_get_space_banner($space_id, $banner_position) {
$static_cache =& drupal_static(__FUNCTION__, array());
$static_cache_key = $space_id . ':' . $banner_position;
if (!isset($static_cache[$static_cache_key])) {
$cid = 'oa_appearance:banner:' . $static_cache_key;
if ($cached_value = cache_get($cid)) {
$static_cache[$static_cache_key] = $cached_value->data;
}
if (!isset($static_cache[$static_cache_key])) {
$space = node_load($space_id);
// Default banner settings.
$banner = array(
'position' => 0,
'image' => array(),
'text' => '',
'slogan' => '',
'stretch' => FALSE,
);
// The site-wide banner position.
$site_position = variable_get('oa_site_banner_position', 0);
// Get the Space's 'Banner position'. If it's set to '- None -', then we
// set the position to -1 to indicate that we don't want to override the
// site default - which is different than 'Hidden', ie. a position of 0.
$space_position = !empty($space) ? field_get_items('node', $space, OA_SPACE_BANNER_POSITION) : array();
$space_position = isset($space_position[0]['value']) ? $space_position[0]['value'] : -1;
// Only attempt to figure out the banner settings if the Space's
// 'Banner position' isn't set to 'Hidden'.
if ($space_position != 0) {
// First, check if the Space is overriding the banner image. If so, we
// use its banner settings.
$space_image = !empty($space) ? field_get_items('node', $space, 'field_oa_banner') : array();
$space_image = !empty($space_image) ? $space_image[0] : NULL;
if ($space_image && $space_position == $banner_position) {
$banner['position'] = $space_position;
$banner['image'] = array(
'path' => $space_image['uri'],
'width' => $space_image['width'],
'height' => $space_image['height'],
'alt' => $space_image['alt'],
'title' => $space_image['title'],
'attributes' => array(
'class' => array(
'oa-banner-overlay-img',
),
),
);
// Space image is always stretched.
$banner['stretch'] = TRUE;
$space_text = field_view_field('node', $space, 'field_oa_banner_text', array(
'label' => 'hidden',
));
if (!empty($space_text)) {
$banner['text'] = drupal_render($space_text);
}
}
else {
$parent_nids = oa_core_get_parents($space_id);
$parent = !empty($parent_nids[0]) ? node_load($parent_nids[0]) : NULL;
if ($parent && $parent->type == 'oa_space') {
$banner = oa_appearance_get_space_banner($parent->nid, $banner_position);
}
elseif ($banner_position == $site_position) {
$banner['position'] = $site_position;
// Get the site-wide image.
$site_stretch = variable_get('oa_banner_stretch', FALSE);
$site_file = NULL;
$site_fid = variable_get('oa_site_banner', '');
if ($site_fid && ($site_file = file_load($site_fid))) {
// Banner successfully loaded.
}
elseif (variable_get('oa_banner_default', TRUE)) {
// Use the default banner image.
$site_file = oa_core_get_banner_default();
}
if ($site_file) {
$banner['image'] = array(
'path' => $site_file->uri,
'width' => !empty($site_file->metadata['width']) ? $site_file->metadata['width'] : 0,
'height' => !empty($site_file->metadata['height']) ? $site_file->metadata['height'] : 0,
'alt' => t('Site banner'),
'attributes' => array(
'class' => $site_stretch ? array(
'oa-banner-overlay-img',
) : array(
'oa-banner-img',
),
),
);
$banner['stretch'] = $site_stretch;
}
// Get the site-wide text.
$banner['text'] = variable_get('oa_banner_sitename', TRUE) ? variable_get('site_name', '') : '';
$banner['slogan'] = variable_get('oa_banner_siteslogan', FALSE) ? variable_get('site_slogan', '') : '';
}
}
}
// Store in the cache for later.
$static_cache[$static_cache_key] = $banner;
cache_set($cid, $banner);
}
}
return $static_cache[$static_cache_key];
}