Skip to content

Instantly share code, notes, and snippets.

@pcambra
Created May 10, 2018 00:43
Show Gist options
  • Save pcambra/ba15d74eb697833a9bd9aea261882d08 to your computer and use it in GitHub Desktop.
Save pcambra/ba15d74eb697833a9bd9aea261882d08 to your computer and use it in GitHub Desktop.
How to add a pane to a node with panelizer programmatically
<?php
// This code can be used in a hook_update_n to add a custom pane to an existing display in panelizer.
// Example variables used in the code below.
$nid = 1;
$pane_machine_name = 'my_example_custom_pane';
$region = 'content';
$position = 0;
// Load the node and save its display as modified, this is required so panelizer knows there's new stuff.
$node = node_load($nid);
$node->panelizer['page_manager']->display_is_modified = TRUE;
node_save($node);
// Change the display.
$display = panels_load_display($node->panelizer['page_manager']->display->did);
$new_pane = panels_new_pane($pane_machine_name, $pane_machine_name, TRUE);
$new_pane->panel = $region;
$new_pane->position = $position;
$display->panels['main-content'][] = $new_pane->pid;
$display->content[$new_pane->pid] = $new_pane;
panels_save_display($display);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment