-
-
Save mcortes19/a99d424636af8480a1d7174a88570c74 to your computer and use it in GitHub Desktop.
How to add a pane to a node with panelizer programmatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Relevants URLs:
https://www.previousnext.com.au/blog/updating-panelizer-content-programmatically
http://www.ygerasimov.com/panels-panelizer-snippets