function oa_related_oa_paragraph_content_render in Open Atrium Related Content 7.2
Render function for the paragraph_content bundle.
1 string reference to 'oa_related_oa_paragraph_content_render'
- oa_related_oa_related_field_info in ./
oa_related.paragraphs.info.inc - @file Used to define information for specific fields on paragraph entities. For now these fields are of the 'Widget type' => 'Select list'.
File
- ./
oa_related.paragraphs.inc, line 215 - Render various paragraph types.
Code
function oa_related_oa_paragraph_content_render(&$vars, $bundle, $field_name, $value) {
if (!isset($value)) {
// This means - None - has been selected. Don't render anything we just use this
// as a entity reference without a display.
$vars['oa_related_content'] = '';
}
else {
switch ($value) {
case 'table':
if (!empty($vars['field_oa_related_content'])) {
// For related files, convert to a table of links with file size info
$icon_directory = variable_get('file_icon_directory', drupal_get_path('module', 'file') . '/icons');
$rows = array();
$header = array(
'',
t('Document'),
t('Download'),
t('Size'),
t('Modified'),
'',
);
foreach ($vars['field_oa_related_content'] as $key => $item) {
$node = $item['entity'];
$file = isset($node->field_oa_media[LANGUAGE_NONE][0]) ? (object) $node->field_oa_media[LANGUAGE_NONE][0] : NULL;
$icons = oa_related_make_icons($node, $file);
if (!empty($node->field_oa_media[LANGUAGE_NONE])) {
foreach ($node->field_oa_media[LANGUAGE_NONE] as $index => $field) {
$file = (object) $field;
$icon = file_icon_url($file);
$uri = file_entity_download_uri($file);
if (node_access('view', $node)) {
$rows[] = array(
theme('image', array(
'path' => $icon,
)),
l($node->title, 'node/' . $node->nid),
l($file->filename, $uri['path'], $uri['options']),
format_size($file->filesize),
array(
'data' => format_date($node->changed, 'short'),
'class' => 'oa-table-noborder',
),
array(
'data' => implode(' ', $icons),
'class' => 'oa-table-actions oa-table-noborder',
),
);
}
}
}
else {
$rows[] = array(
theme('image', array(
'path' => url($icon_directory . '/application-octet-stream.png'),
)),
array(
'data' => l($node->title, 'node/' . $node->nid),
'colspan' => 3,
),
format_date($node->changed, 'short'),
array(
'data' => implode(' ', $icons),
'class' => 'oa-table-actions oa-table-noborder',
),
);
}
}
$element = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
$vars['oa_related_content'] = render($element);
}
$vars['theme_hook_suggestions'][] = 'oa_related_paragraphs_content_render';
break;
case 'preview':
if (!empty($vars['field_oa_related_content'])) {
$rows = array();
$icon_directory = variable_get('file_icon_directory', drupal_get_path('module', 'file') . '/icons');
foreach ($vars['field_oa_related_content'] as $key => $item) {
$row = array();
$node = $item['entity'];
if (node_access('view', $node)) {
$body = oa_core_get_summary($node);
$output = '<h3 class="oa-table-title">' . l($node->title, 'node/' . $node->nid) . '</h3>' . $body;
$files = array();
if (isset($node->field_oa_media)) {
$files = field_view_field('node', $node, 'field_oa_media', 'featured');
}
$file = NULL;
if (!empty($files['#items'])) {
$file = (object) $files['#items'][0];
$row[] = array(
'data' => $files,
'width' => '258',
);
$row[] = array(
'data' => $output,
'class' => 'oa-table-body oa-table-noborder',
);
}
else {
$row[] = array(
'data' => $output,
'class' => 'oa-table-body oa-table-noborder',
'colspan' => 2,
);
}
$icons = oa_related_make_icons($node, $file);
$row[] = array(
'data' => implode(' ', $icons),
'class' => 'oa-table-actions oa-table-noborder',
);
$rows[] = $row;
}
}
$element = array(
'#theme' => 'table',
'#rows' => $rows,
);
$vars['oa_related_content'] = render($element);
}
$vars['theme_hook_suggestions'][] = 'oa_related_paragraphs_content_render';
break;
case 'list':
if (!empty($vars['field_oa_related_content'])) {
$items = array();
foreach ($vars['field_oa_related_content'] as $key => $item) {
$node = $item['entity'];
if (node_access('view', $node)) {
$items[] = l($node->title, 'node/' . $node->nid);
}
}
$element = array(
'#theme' => 'item_list',
'#items' => $items,
'#type' => 'ul',
);
$vars['oa_related_content'] = render($element);
}
$vars['theme_hook_suggestions'][] = 'oa_related_paragraphs_content_render';
break;
case 'full':
if (!empty($vars['field_oa_related_content'])) {
$title = count($vars['field_oa_related_content']) == 1 ? t('Related') . ' ' . node_type_get_name($vars['field_oa_related_content'][0]['entity']) : $vars['content']['field_oa_related_content']['#title'];
$vars['oa_related_content'] = array();
foreach ($vars['field_oa_related_content'] as $key => $item) {
$node = $item['entity'];
if (node_access('view', $node)) {
$file = isset($node->field_oa_media[LANGUAGE_NONE][0]) ? (object) $node->field_oa_media[LANGUAGE_NONE][0] : NULL;
if ($key > 0) {
$vars['multiple_content'] = TRUE;
}
$icons = oa_related_make_icons($node, $file);
if (!empty($icons)) {
$oa_icons = array(
'#prefix' => '<div class="oa-table-actions pull-right">',
'#markup' => implode(' ', $icons),
'#suffix' => '</div>',
'#weight' => $key + 0.75,
);
$vars['oa_related_content'][$key]['icons'] = render($oa_icons);
}
$node_view = node_view($node, 'featured');
$node_view['#weight'] = $key + 1;
$vars['oa_related_content'][$key]['node'] = render($node_view);
}
}
// Only set title if at least one item can be viewed.
if (!empty($vars['oa_related_content'])) {
$vars['title'] = $title;
}
}
$vars['theme_hook_suggestions'][] = 'oa_related_paragraphs_content_render';
break;
}
}
}