If Page Manager is enabled on a site, it's possible to peek in on any task's context with page_manager_get_current_page(), so why not bring this to blocks?

When mini panels have context, they shouldn't be listed in the block admin page. However, they were appearing due to a typo. In panels_mini_block_info():

    if (empty($panel_mini->disabled) && empty($panel_mini->requiredcontext)) {

should be:

    if (empty($panel_mini->disabled) && empty($panel_mini->requiredcontexts)) {

This patch fixes that typo but continues to include those mini panels which have required contexts if page_manager is enabled.

In panels_mini_block_view(), when page_manager is enabled, it grabs the context of the current page, matches it with the required contexts of the mini panel, and merges the contexts from the current page with any contexts from the mini panel.

It's a simple patch that does a lot! I can now make blocks that react to and extend the current page's context.

The attached mini-panel-test.txt can be imported to mini panels for testing. It creates a mini panel that displays the body of a node when the page manager task node_view is enabled and has a variant that outputs a page (i.e. a Panel display).

CommentFileSizeAuthor
#1 block_context-1621588-1.patch3.36 KBAnonymous (not verified)
mini-panel-test.txt1.49 KBAnonymous (not verified)
panels_mini_context.patch1.89 KBAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

This is more complicated patch than I originally believed. Here's the latest incarnation of it. It works... so far.

phayes’s picture

This is awesome. Thanks bangpound.

merlinofchaos’s picture

Status: Needs review » Fixed
+++ b/panels_mini/panels_mini.moduleundefined
@@ -74,7 +74,7 @@ function panels_mini_block_info() {
+    if (empty($panel_mini->disabled) && (module_exists('page_manager') | empty($panel_mini->requiredcontexts))) {

| is a bitwise or, I think you want || in this one.

Otherwise this seems interesting, so I've gone ahead and committed it.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

markdown converted to html

  • Commit c9041a5 on 7.x-3.x, 7.x-3.x-i18n, 8.x-3.x authored by bangpound, committed by merlinofchaos:
    Issue #1621588 by bangpound: Added Pass page manager context to block...