t('Embed content'), 'description' => t('Embed node content into the text.'), 'process callback' => 'shortcode_embed_content_shortcode_node', //'settings callback' => '_shortcode_settings_form', TODO 'tips callback' => 'shortcode_embed_content_node_tip', 'default settings' => array(), ); return $shortcodes; } /** * Embed a node content into the text * * Calling * [embed_content nid=X /] * * Other shortcode parameters * * class - additional class to the node * * If no nid given the result will be empty * * TODO: implement view_mode - other than teaser or full! */ function shortcode_embed_content_shortcode_node($attrs, $text) { $attrs = shortcode_attrs( array( 'nid' => 0, 'class' => '', 'view_mode' => 'teaser', // TODO: actually the full mode is does not work 'show_title' => FALSE, 'show_submitted' => FALSE, 'show_meta' => FALSE, 'show_terms' => FALSE, 'show_links' => FALSE, ), $attrs ); if (!empty($attrs['nid'])) { $node = node_load($attrs['nid']); // add embedded flag to the node if (empty($node) || !$node->status || !node_access('view', $node)) { return ''; } $node->shortcode_embedded = TRUE; } else { return ''; } $params = new stdClass(); $params->embedded = TRUE; $params->view_mode = $params->original_view_mode = $attrs['view_mode']; $params->show_title = shortcode_bool($attrs['show_title']); $params->show_meta = shortcode_bool($attrs['show_meta']); $params->show_submitted = shortcode_bool($attrs['show_submitted']); $params->show_terms = shortcode_bool($attrs['show_terms']); $params->show_links = shortcode_bool($attrs['show_links']); // insert the original attributes to the params $params->attrs = $attrs; $node->shortcode = $params; if ('full' == $attrs['view_mode']) { $params->view_mode = 'teaser'; } $content = node_view($node, $params->view_mode); return render($content); } // shortcode_embed_content_shortcode_node() function shortcode_embed_content_node_tip($format, $long) { $output = ''; $output = '
[embed_content nid=nodeid (class="additional class")/] '; if ($long) { $output .= 'Embed a node by nid into the text. Additional class names can be added by the class parameter.
'; } else { $output .= 'Embed a node by nid into the text. Additional class names can be added by the class parameter.'; } return $output; } // shortcode_embed_content_node_tip() /** * Implementation of hook_preprocess_node() * TODO: implement dynamic embedding! */ function shortcode_embed_content_preprocess_node(&$vars) { if (isset($vars['shortcode']) && $vars['shortcode']->embedded) { $vars['template_files'][] = "node-shortcode--default"; $vars['template_files'][] = 'node-shortcode--' . $vars['type']; } }