On node pages, contextual links (for editing the current node) are stored/rendered in the $title_suffix template variable. This variable is not rendered within the PageTitle block, and as a result contextual node links are not showing up...

Not sure what a good solution to this problem is, because the Page Title block has its own contextual link ("Configure Block"), so simply rendering $title_suffix inside the block will probably lead to a visual conflict. I guess for me it would make most sense to have the contextual node links attached to the main page content (i.e. the node display)...

Any tips on how to do that? Ideas for a "proper solution" or for what a patch should look like?


#1 1309660-2-contextual-link-fix.patch779 bytesbforchhammer
Members fund testing for the Drupal project. Drupal Association Learn more


bforchhammer’s picture

Project: Delta » Omega
Version: 7.x-3.0-beta8 » 7.x-3.x-dev
779 bytes

Hm, I managed to get them to display by overriding omega's node.tpl.php and moving the $title_before and $title_after outside the <header> tag (see patch).

Should this maybe be changed in omega? I don't know if $title_before and $title_after are used for anything else, but if contextual_links are the only usecase then it would probably make sense!?

bforchhammer’s picture

Title: PageTitle block "breaks" contextual links (delta blocks) » Ensure $title_suffix is always rendered (i.e. fix contextual links)
Status: Active » Needs work

Also, on a similar note I found that contextual links were not being rendered for views pages either.

The source of that problem lies in views module's implementation of contextual links: #876772-6: Better contextual link integration for blocks and pages

David Rothstein: The one part that is definitely hacky is the code for getting the links to appear in the correct place on page displays (i.e., for making sure the dotted outline in http://drupal.org/files/issues/views-contextual-links-page.png is drawn in the correct place). It needed some workarounds due to limitations in Drupal core, and because of that, the code winds up being semi-theme-dependent so it's not guaranteed to work well always. I'm not too happy with that. In practice, though, I tried it out on a bunch of D7 themes and it works great with all of them (with the notable exception of admin themes, such as Seven, which tend to have markup that is less well-organized for contextual links).

The Omega theme does not render the $title_suffix variable on the page level, preventing contextual links from being displayed.

The following hook solves the problem for me. Note that the location of the "main content block" (system_main) may by different depending on the theme, so this might have to be adjusted for other themes...

 * Implements hook_page_alter().
function MYTHEME_page_alter(&$vars) {
  // Omega does not render $title_suffix on the page level, so this moves
  // contextual links from the page level back into the main content area.
  if (isset($vars['#contextual_links'])) {
    $vars['content']['content']['content']['system_main']['#contextual_links'] = $vars['#contextual_links'];
    $vars['content']['content']['content']['system_main']['#views_contextual_links_info'] = $vars['#views_contextual_links_info'];
    unset($vars['#contextual_links'], $vars['#views_contextual_links_info']);

As a side effect this also fixes #1284872: All Contextual Links are triggered..

marcoka’s picture

Category: feature » bug
Priority: Normal » Major

the patch does not fix it for me. in my opinion this is a bug not a feature request.

marcoka’s picture

Priority: Major » Normal
rlhawk’s picture

Here's the workaround I'm using for now to solve this issue. The code is largely taken from Views's views_preprocess_html function. The problem is that the class that Views looks for in that function (views_contextual_links_info) is not in the HTML template in Omega; it's in the Page template. Ultimately, it would good to fix that in Omega, if it doesn't break something else. In the meantime, this theme preprocess function should work. It should go either in preprocess/preprocess-page.inc or in template.php.

function THEMENAME_alpha_preprocess_page(&$vars) {
  if (!empty($vars['page']['#views_contextual_links_info'])) {
    $key = array_search('contextual-links-region', $vars['attributes_array']['class']);
    if ($key !== FALSE) {

      // Add the JavaScript, with a group and weight such that it will run
      // before modules/contextual/contextual.js.
      drupal_add_js(drupal_get_path('module', 'views') . '/js/views-contextual.js', array('group' => JS_LIBRARY, 'weight' => -1));
himerus’s picture

Status: Needs work » Fixed

The actual solution for this is quite simple via a quick template edit.

<div<?php print $attributes; ?>>
  <div<?php print $content_attributes; ?>>
    <a id="main-content"></a>
    <?php print render($title_prefix); ?>
    <?php if ($title): ?>
    <?php if ($title_hidden): ?><div class="element-invisible"><?php endif; ?>
    <h1 class="title" id="page-title"><?php print $title; ?></h1>
    <?php if ($title_hidden): ?></div><?php endif; ?>
    <?php endif; ?>
    <?php print render($title_suffix); ?>
    <?php if ($tabs && !empty($tabs['#primary'])): ?><div class="tabs clearfix"><?php print render($tabs); ?></div><?php endif; ?>
    <?php if ($action_links): ?><ul class="action-links"><?php print render($action_links); ?></ul><?php endif; ?>
    <?php print $content; ?>
    <?php if ($feed_icons): ?><div class="feed-icon clearfix"><?php print $feed_icons; ?></div><?php endif; ?>

The <?php print render($title_prefix); ?> and <?php print render($title_suffix); ?> should appear outside of the conditional <?php if ($title): ?>

This fix is going in the 3.1 release

himerus’s picture

Forgot to mention that this template edit is in region--content.tpl.php for page level title rendering, and also in node.tpl.php for default teaser type title rendering.

bforchhammer’s picture

Thanks himerus, that's good news :-)

echoz’s picture

I submitted this patch #1270552: $title_prefix, $title_suffix not outside "if ($title)" in region--content.tpl.php (just for region--content.tpl.php), but it fell between the cracks, and today got marked as duplicate even though it preceded this issue by over a month. Also, when marking as duplicate, it's helpful to indicate the issue it is a duplicate for.

amaria’s picture

Yeah this doesn't work for me either on node teasers. The title_prefix element is empty. The title_suffix element contains the contextual links but the links are not appearing.

amaria’s picture

Scratch that. It does work. It just doesn't work with Contextual Flyout Links. Bummer.

amaria’s picture

For anyone interested in making Contextual Flyout Links work for all regions in Omega, try my patch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mixhael’s picture

Status: Closed (fixed) » Needs review

The issue that the whole page of a view becomes a contextual links region, resulting in all contextual links being triggered at once is still not solved. I posted it here: http://drupal.org/node/1326744, but it was recommended to continue in this thread

Status: Needs review » Needs work

The last submitted patch, 1309660-2-contextual-link-fix.patch, failed testing.

Cellar Door’s picture

Assigned: Unassigned » fubhy

fubhy - any thoughts as to why this would be happening?

rlhawk’s picture

Here is the code I'm using to address the Views contextual links issue. It's a shorter version of what I posted above, without the drupal_add_js, since the necessary JS is already added by Views. It's not a perfect solution, but it removes the contextual link trigger from the whole page. The code should go in either THEMENAME/preprocess/preprocess-page.inc or THEMENAME/template.php.

function test_alpha_preprocess_page(&$vars) {
  if (!empty($vars['page']['#views_contextual_links_info'])) {
    $key = array_search('contextual-links-region', $vars['attributes_array']['class']);
    if ($key !== FALSE) {
rlhawk’s picture

"test" is the name of my theme, in the code above. Of course, change it to whatever your theme name is.

Paul Broon’s picture

EDIT: Well, turns out the core module "Contextual Links" got deactivated along the way of creating and developing a subtheme. Re-enabling shows all the contextual links again and I can confirm that 3.1 (and 3.1+4-dev) has all contextual links in the right spot.

EDIT 2: Now that contextual links are present again, I experience the issue with triggering all contextual menus by entering viewpoint. Patch from #17 resolves that issue. When hovering main content on view pages, contextual menus are triggered for both views and all nodes but this also happens with Bartik; so it's not Omega related.


Hey there,
so I ran into a similar bug. There are no contextual links displayed at all, neither for node pages nor for views.
While using 7.x-3.1, $vars['page'] contains correct '#contextual_links' as well as '#views_contextual_links_info'; however, both $vars['title_prefix'] and $vars['title_suffix'] are empty arrays.
The HTML ouput contains no divs for title's suffix/prefix. I tried all provided patches as in #2, #5 and #17 to no luck.
I tried Omega 7.x-3.1+4-dev (currently latest dev) but again no change.
What am I missing? On which level within $vars should '#contextual_links' and '#views_contextual_links_info' reside to be rendered or, respectively, at which point are these attached to title_suffix?
Thanks in advance,

Cellar Door’s picture

Assigned: fubhy » himerus
Category: bug » feature
Status: Needs work » Reviewed & tested by the community

Should this be sent to Views as an issue or added to 3.2 in the template.php?

Wickedweb.Mark’s picture

Version: 7.x-3.x-dev » 7.x-1.0
Assigned: himerus » Unassigned
Category: feature » bug
Priority: Normal » Minor
Status: Reviewed & tested by the community » Needs work

Tried and tested fixes to all but fail.

Resorted to nasty hack as per below:

contexualfix = function() {
	if (jQuery('#page').hasClass('contextual-links-region')) {
tregismoreira’s picture

Hey guys, somebody founds a definitive solution for this boring issue (without jquery)?

tregismoreira’s picture

Wow, #2 works perfectly for me! Thanks a lot ;)

kkasischke’s picture

The patch in this Views issue worked for me: Contextual links added to page element if 'page' view is displayed

steinmb’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

7.x-1.x is unsupported, closing.