2

I've been trying to understand this for a while now, but I find the documentation either to lacking, or maybe I just don't understand what I'm looking for. Could anyone enlighten me on how to implement them?

One thing I'm trying to do is to be able to have contextual menus for each node in a list of nodes (loaded using node_load_multiple) that I'm sending along to a theme() function and looping through inside the .tpl.php

3

I'll put my temporary solution here for now anyway in case it will help someone.

What I did was just creating a new theme function (?) in my module

$themes['contextual'] = array(
    'template' => 'contextual',
    'variables' => array('links' => array(), 'destination' => null)
);

Then I defined my contextual.tpl.php

<div class="contextual-links-wrapper">
    <ul class="contextual-links">
        <?php foreach($links as $url => $title): ?>
        <li>
            <?php echo l($title, $url, 
                array('query' => array('destination' => $destination))) ?>
        </li>
        <?php endforeach; ?>
    </ul>
</div>

Finally, to use it, wherever there is a need for a contextual menu, add the class contextual-links-region to the container div of the node (or whatever), and inside the div I use my function, for example:

<?php echo theme('contextual', array('destination' => 'node/'.arg(1),
    'links' => array('node/'.$somenode->nid.'/edit', t('Edit node')))); ?>
1
  • Is this solution working, Actually i need to use a context menu with one of my content type field. – Drupal Developer Jul 15 '14 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.