RSS

Newsletter

The CodeKarate Newsletter is the best way for technical ninjas to keep their swords sharpened. Don't worry, we won't flood your inbox and your email address will always remain private.
Back to Top

Adding a minipanel with context inside quicktabs

I use the quicktabs module occasionally to display tabbed content. I recently ran into a situation with a complex user profile that caused me to have to display a minipanel with contexts inside a quicktabs block. There was no easy way that I could find to pass the contexts through the quicktabs block to my minipanel. Because of this, I came up with this solution (be warned, it is a little bit of an ugly workaround).

/**
 * Implements hook_block().
 */
function MYMODULE_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks = array();
    $blocks[0] = array('info' => t('My Mini Panel'),);
    return $blocks;
  }
  else if ($op == 'view') {
    switch ($delta) {
      case 0:
        $user = menu_get_object('user_uid_optional');
 
        $node = content_profile_load('CONTENT_PROFILE_TYPE', $user->uid);
 
        //add contexts to the mini panel
        ctools_include('context');
        $panel_mini = panels_mini_load('MY_MINI_PANEL');
 
        $user_context = new StdClass();
        $user_context->type = 'user';
        $user_context->data = $user;
 
        $node_context = new StdClass();
        $node_context->type = 'node';
        $node_context->data = $node;
 
        $contexts =  array($node_context, $user_context);
        $context = ctools_context_match_required_contexts($panel_mini->requiredcontexts, $contexts);
        $panel_mini->context = $panel_mini->display->context = ctools_context_load_contexts($panel_mini, FALSE, $context);
 
        $block = array(
          'subject' => t('My Mini Panel'),
          'content' => panels_render_display($panel_mini->display),
        );
        return $block;
        break;
    }
  }
}

Discussions

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <blockquote> <img>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <css>, <html>, <php>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <python>, <ruby>. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.