1

In Drupal 7, you could look for $node->panelizer or use page_manager_get_current_page() to check if the current page uses a panelizer layout. How do you do that in Drupal 8?

I'm trying to add a body class if the current page contains a specific pane.

1

I'm not sure if this is quite what you're after, but these hooks will fire if your page is using panelizer.

/**
 * Implements hook_preprocess_panels_pane().
 */
function YOURTHEME_preprocess_panels_pane(&$$variables) {
  // If this triggers then you are in a panels pane.
}

OR

/**
 * Implements hook_panels_pane_content_alter().
 */
 function YOUR_MODULE_panels_pane_content_alter($content, $pane, $args, $contexts) {
  // If this triggers then you are altering panels content.
}

If you want to check for panelizer in the node you could try something like this:

$node = \Drupal::routeMatch()->getParameter('node');
if ($node->hasField('panelizer')) {
  // Do stuff
}
0
0

Turns out you do have access to $node->panelizer. So here's what I did:

function MYMODULE_preprocess_html(&$vars) {
  $node = \Drupal::routeMatch()->getParameter('node');
  if ($node instanceof \Drupal\node\NodeInterface) {
    if (isset($node->panelizer)) {
      $panelizer = $node->panelizer->getValue();
      // do whatever checks are needed
      // and use $vars['attributes']->addClass('MYCLASS') when ready
    }
  }
}

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.