Last active
February 17, 2017 06:09
-
-
Save lhuria94/27cb862015ea64ec5f5a7f8b146f49ac to your computer and use it in GitHub Desktop.
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 | |
$panelizer_nodes = db_select('node', 'n'); | |
$panelizer_nodes->leftjoin('panelizer_entity', 'e', 'e.entity_id = n.nid'); | |
$panelizer_nodes->fields('e', array('entity_id')); | |
$panelizer_nodes->condition('entity_type', 'node'); | |
$panelizer_nodes->condition('did', 0, '<>'); | |
$panelizer_nodes->condition('n.status ', 1, '='); | |
$panelizer_nodes->condition('n.type', 'content_type'); | |
$result = $panelizer_nodes->groupBy('e.entity_id')->execute()->fetchCol('entity_id'); | |
$nodes = node_load_multiple($result); | |
foreach ($nodes as $nid => $node) { | |
// Set region based on layout. | |
switch ($node->panelizer['page_manager']->display->layout) { | |
case 'onecol_basic': | |
$region = 'strip'; | |
break; | |
} | |
// Check if matching type. | |
if ($region) { | |
$panes = array(); | |
$my_block_pane_exists = FALSE; | |
// Load the display. | |
if ($display = panels_load_display($node->panelizer['page_manager']->display->did)) { | |
// Get this display's panes. | |
$panes = $display->content; | |
// Reset the panes. | |
$display->content = array(); | |
$display->panels[$region] = array(); | |
// Loop through and add in our new pane. | |
foreach ($panes as $pid => $pane) { | |
if ($pane->type == 'entity_field' && $pane->subtype == 'node:field_blog_author') { | |
$my_block_pane_exists = TRUE; | |
} | |
// If my_block pane already exists we can skip this. | |
// Set content. | |
$display->panels[$region][] = $pid; | |
$display->content[$pid] = $pane; | |
// Add a new pane after the node_title pane. | |
$new_pane = panels_new_pane('entity_field', 'node:field_blog_author', TRUE); | |
$new_pane->panel = $region; | |
$display->panels[$region][] = $new_pane->pid; | |
$display->content[$new_pane->pid] = $new_pane; | |
} | |
// Finished reordering pane's, now save. | |
if (!$my_block_pane_exists) { | |
panels_save_display($display); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment