function party_attached_entity_content_type_render in Party 7
Same name and namespace in other branches
- 8.2 plugins/content_types/attached_entity/attached_entity.inc \party_attached_entity_content_type_render()
Render the custom content type.
File
- plugins/
content_types/ attached_entity/ attached_entity.inc, line 67 - Plugin to handle attached entity content types
Code
function party_attached_entity_content_type_render($subtype, $conf, $panel_args, $contexts) {
$context = $contexts[$conf['context']];
if (empty($context) || empty($context->data)) {
return;
}
// Get a shortcut to the party.
$party = $context->data;
$data_set_name = $subtype;
$data_set = party_get_data_set_info($data_set_name);
$empty = FALSE;
if (empty($conf['bypass_access']) && !party_access('view', $party, $data_set)) {
return;
}
// Get the attached entities in this data set
$attached_entities = $party
->getDataSetController($data_set_name)
->getEntities();
// If there are none, do not render anything
if (empty($attached_entities)) {
$empty = TRUE;
}
// Remove all unneccesary attached entities if we're not showing them all
if ($conf['delta'] != -1) {
$attached_entity_list = array_values($attached_entities);
// If one with the right delta exists...
if (isset($attached_entity_list[$conf['delta']])) {
// Replace the array with an array just containing the one attached entity
$attached_entity = $attached_entity_list[$conf['delta']];
$attached_entities = array(
$conf['delta'] => $attached_entity,
);
}
else {
$empty = TRUE;
}
}
// $attached_entities should now be alist of all the ones we want to show so lets convert this into a list of entities
$entities = array();
foreach ($attached_entities as $attached_entity) {
$entities[] = $attached_entity;
}
if (empty($entities)) {
$empty = TRUE;
}
if ($empty && empty($conf['show_empty'])) {
return FALSE;
}
else {
if ($empty) {
$content = ctools_context_keyword_substitute($conf['empty_message'], array(), $contexts);
}
else {
$content = entity_view($data_set['entity type'], $entities, $conf['view_mode']);
}
}
$block_delta = $data_set_name;
if ($conf['delta'] != -1) {
$block_delta .= '_' . $conf['delta'];
}
// Build the content type block.
$block = new stdClass();
$block->module = 'attached_entity';
$block->title = $data_set['label'];
$block->content = $content;
$block->delta = $block_delta;
return $block;
}