Skip to content

Instantly share code, notes, and snippets.

@dsnopek
Created November 19, 2014 16:19
Show Gist options
  • Save dsnopek/a17b1ba622616938cb93 to your computer and use it in GitHub Desktop.
Save dsnopek/a17b1ba622616938cb93 to your computer and use it in GitHub Desktop.
hook_update_N() to replace "Existing node" panes with Panopoly's "Content item" pane (Drupal)
/**
* Convert 'Existing node' panes to 'Content item' panes.
*/
function hook_update_N() {
// We're going to load the panes directly from the 'panels_pane' table and
// replace them with the new pane, reusing the same IDs and everything.
// Don't try this at home, kids!
$result = db_query("SELECT * FROM {panels_pane} WHERE type = 'node' AND subtype = 'node'");
$serialized_fields = array('access', 'configuration', 'cache', 'style', 'css', 'extras', 'locks');
foreach ($result as $pane) {
// Unserialize all the serialized fields.
foreach ($serialized_fields as $field) {
$pane->$field = unserialize($pane->$field);
}
// Load the original node, so we can get it's title.
if ($node = node_load($pane->configuration['nid'])) {
$pane->type = 'views_panes';
$pane->subtype = 'panopoly_widgets_general_content-piece_of_content';
if ($pane->configuration['build_mode'] == 'full') {
$view_mode = 'subpane';
} else {
$view_mode = $pane->configuration['build_mode'];
}
$pane->configuration = array(
'fields_override' => array(
'field_featured_image' => TRUE,
'title' => TRUE,
'created' => TRUE,
'name' => TRUE,
),
'exposed' => array(
'title' => $node->title,
'type' => 'All',
),
'view_settings' => 'nodes',
'header_type' => 'none',
'view_mode' => $view_mode,
);
drupal_write_record('panels_pane', $pane, array('pid'));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment