Exemplo n.º 1
0
/**
 * Implements template_preprocess_toolbar()
 * Put the node tabs and local actions into the top admin toolbar area
 */
function frame_preprocess_toolbar(&$vars)
{
    $vars['toolbar']['toolbar_drawer'][0]['menu_local_tabs'] = menu_local_tabs();
    $vars['toolbar']['toolbar_drawer'][0]['menu_local_tabs']['#primary'][] = menu_local_actions();
}
Exemplo n.º 2
0
/**
 * Implements hook_preprocess_node().
 */
function bvng_preprocess_node(&$variables)
{
    /* Add theme hook suggestion for nodes of taxonomy/term/%
     */
    if (isset($variables['requested_path'])) {
        if (strpos($variables['requested_path'], 'taxonomy/term') !== FALSE) {
            array_push($variables['theme_hook_suggestions'], 'node__taxonomy' . '__generic');
        }
    } elseif (isset($variables['current_path'])) {
    }
    /* Prepare the prev/next $node of the same content type.
     */
    if ($variables['node']) {
        switch ($variables['node']->type) {
            default:
                $next_node = node_load(prev_next_nid($variables['node']->nid, 'prev'));
        }
        $next_node = $next_node->status == 1 ? $next_node : NULL;
        // Only refer to published node.
        $variables['next_node'] = $next_node;
    }
    /* Prepare $cchunks, $anchors and $elinks for type "generictemplate"
     * @see http://drupal.stackexchange.com/questions/35355/accessing-a-field-collection
     */
    // Prepare $cchunks.
    if ($variables['node']->type == 'generictemplate' && !empty($variables['field_cchunk'])) {
        $fields_collection = field_get_items('node', $variables['node'], 'field_cchunk');
        $cchunks = array();
        foreach ($fields_collection as $idx => $data) {
            $cchunks[$idx] = field_collection_item_load($fields_collection[$idx]['value']);
        }
        $variables['cchunks'] = $cchunks;
        // Prepare title, content and sidebar for each chunk.
        $cchunks_title = array();
        $cchunks_content = array();
        $cchunks_sidebar = array();
        $anchors = array();
        $elinks = array();
        foreach ($variables['cchunks'] as $k => $cchunk) {
            $cchunks_title[$k] = _bvng_get_field_value('field_collection_item', $cchunk, 'field_title');
            $cchunks_content[$k] = _bvng_get_field_value('field_collection_item', $cchunk, 'field_sectioncontent');
            $sidebar_fields = array('anchors' => 'field_anchorlinkslist', 'elinks' => 'field_externallinkslist');
            foreach ($sidebar_fields as $var => $sidebar_field) {
                $field_links = array();
                $field_links[] = field_get_items('field_collection_item', $cchunk, $sidebar_field);
                foreach ($field_links as $i => $field_link) {
                    foreach ($field_link as $f_link) {
                        $cat_var =& ${$var};
                        $cat_var[$k][] = field_collection_item_load($f_link['value']);
                    }
                }
            }
            $cchunks_sidebar[$k] = '';
            if (!empty($anchors[$k])) {
                foreach ($anchors[$k] as $anchor) {
                    if ($anchor !== FALSE) {
                        $anchors_title = _bvng_get_field_value('field_collection_item', $anchor, 'field_anchorlinkslisttitle');
                        $anchors_links = _bvng_get_field_value('field_collection_item', $anchor, 'field_anchorlink');
                        $cchunks_sidebar[$k] .= '<h3>' . $anchors_title . '</h3>';
                        $cchunks_sidebar[$k] .= '<ul class="tags">';
                        foreach ($anchors_links as $anchors_link) {
                            $cchunks_sidebar[$k] .= '<li><a href="#' . $anchors_link['link'] . '">' . $anchors_link['title'] . '</a></li>';
                        }
                        $cchunks_sidebar[$k] .= '</ul>';
                    }
                }
            }
            if (!empty($elinks[$k])) {
                foreach ($elinks[$k] as $elink) {
                    if ($elink !== FALSE) {
                        $elinks_title = _bvng_get_field_value('field_collection_item', $elink, 'field_externallinkslisttitle');
                        $elinks_links = _bvng_get_field_value('field_collection_item', $elink, 'field_externallink');
                        $cchunks_sidebar[$k] .= '<h3>' . $elinks_title . '</h3>';
                        $cchunks_sidebar[$k] .= '<ul class="tags">';
                        foreach ($elinks_links as $elinks_link) {
                            $link = array('#theme' => 'link', '#text' => $elinks_link['title'], '#path' => $elinks_link['url'], '#options' => array('attributes' => $elinks_link['attributes']), '#prefix' => '<li>', '#suffix' => '</li>');
                            $cchunks_sidebar[$k] .= render($link);
                        }
                        $cchunks_sidebar[$k] .= '</ul>';
                    }
                }
            }
        }
        $variables['cchunks_title'] = $cchunks_title;
        $variables['cchunks_content'] = $cchunks_content;
        $variables['cchunks_sidebar'] = $cchunks_sidebar;
    }
    /* Get footer fields for data use articles.
     */
    $node_footer = _bvng_get_node_footer_content($variables['node']);
    $variables['node_footer'] = $node_footer;
    /* Get sidebar content
     */
    $sidebar = _bvng_get_sidebar_content($variables['nid'], $variables['vid']);
    $variables['sidebar'] = $sidebar;
    /* Build a combo value consisting of publisher and publishing date
     */
    if ($variables['node']->type == 'resource_ims' && !empty($variables['field_publishing_date']) && !empty($variables['field_publisher'])) {
        /*
         * fix me: It should have been done with "render()" so that we can make use of the format decided in "manage display"
         */
        $publishing_date = _bvng_get_field_value('node', $variables['node'], 'field_publishing_date');
        $publisher = _bvng_get_field_value('node', $variables['node'], 'field_publisher');
        // Friday, April 11, 2014
        $publishing_date = date('l, M d, Y', $publishing_date);
        $publisher_w_date = $publisher . ', ' . $publishing_date;
        $variables['publisher_w_date'] = '<div class="field field-name-field-publisher-w-date field-type-text-long field-label-above">
		<div class="field-label">Publisher&nbsp;</div>
		<div class="field-items">
		<div class="field-item even">' . $publisher_w_date . '</div></div></div>';
    }
    /* Process the date of event.
     */
    if ($variables['node']->type == 'event_ims') {
        $variables['event_date'] = _bvng_get_field_value('node', $variables['node'], 'field_dates');
    }
    /* Process menu_local_tasks()
     */
    global $user;
    // Bring the local tasks tab into node template.
    // @todo To investigate that this doesn't work for data use.
    $variables['tabs'] = menu_local_tabs();
    /* Determine what local task to show according to the role.
     * @todo To implement this using user_permission.
     */
    if (is_array($variables['tabs']['#primary'])) {
        foreach ($variables['tabs']['#primary'] as $key => $item) {
            // We don't need the view tab because we're already viewing it.
            switch ($item['#link']['title']) {
                case 'View':
                    unset($variables['tabs']['#primary'][$key]);
                    break;
                case 'Edit':
                    // Alter the 'edit' link to point to the node/%/edit
                    $variables['tabs']['#primary'][$key]['#link']['href'] = 'node/' . $variables['node']->nid . '/edit';
                    if (!in_array('Editors', $user->roles)) {
                        unset($variables['tabs']['#primary'][$key]);
                    }
                    break;
                case 'Devel':
                    // Alter the 'edit' link to point to the node/%/devel
                    $variables['tabs']['#primary'][$key]['#link']['href'] = 'node/' . $variables['node']->nid . '/devel';
                    if (!in_array('administrator', $user->roles)) {
                        unset($variables['tabs']['#primary'][$key]);
                    }
                    break;
            }
        }
    }
    /* Get also tagged
     */
    $variables['also_tagged'] = _bvng_get_also_tag_links($variables['node']);
    /* Prepare event location
     */
    if (isset($variables['node']->type) && $variables['node']->type == 'event_ims') {
        $markup_location = '';
        $city = _bvng_get_field_value('node', $variables['node'], 'field_city');
        $venuecountry = _bvng_get_field_value('node', $variables['node'], 'field_venuecountry');
        $markup_location .= $city == FALSE ? '' : $city;
        $markup_location .= $city == FALSE && $venuecountry == FALSE ? '' : ', ';
        $markup_location .= $venuecountry == FALSE ? '' : $venuecountry;
    }
    if (strlen($markup_location) !== 0) {
        $variables['event_location'] = $markup_location;
    }
}