Skip to content

Instantly share code, notes, and snippets.

@dsnopek
Created May 30, 2015 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsnopek/20dd0fec4fbc4a4e6ca8 to your computer and use it in GitHub Desktop.
Save dsnopek/20dd0fec4fbc4a4e6ca8 to your computer and use it in GitHub Desktop.
Panopoly: Convert Page Manager pages into Landing Page nodes
function _panopoly_convert_landing_pages() {
ctools_include('export');
// Collect a list of all the page manager pages that are eligable for
// conversion. There are lots of features of page manager pages that don't
// work with Panelizer nodes!
$pages = array();
foreach (ctools_export_load_object("page_manager_pages") as $page) {
// Skip pages that are in code at all (even if they are overridden in the
// database).
if ($page->export_type & EXPORT_IN_CODE) {
continue;
}
// Skip pages that have access rules.
if (!empty($page->access)) {
continue;
}
// Skip pages that have menus that aren't 'Normal menu entry'.
if (!empty($page->menu) && $page->menu['type'] != 'none' && $page->menu['type'] != 'normal') {
continue;
}
// Load the page variants.
$handlers = page_manager_load_task_handlers(page_manager_get_task('page'), $page->name);
// Skip pages that have more than one variant.
if (count($handlers) != 1) {
continue;
}
// Get the only variant.
$handler = reset($handlers);
// Skip variants that aren't Panels displays.
if ($handler->handler != 'panel_context') {
continue;
}
// Skip pages where the variant has selection rules or is in code.
if (($handler->export_type & EXPORT_IN_CODE) || !empty($handler->conf['access']['plugins'])) {
continue;
}
// Load the Panels display.
$display = panels_load_display($handler->conf['did']);
// Before creating the node, we need to disable the Page Manager page so
// that the URL is available for the alias.
ctools_export_set_object_status($page, 0);
$pages[] = array(
'page' => $page,
'handler' => $handler,
'display' => $display,
);
}
// Rebuild the menu now that we've disabled all the page manager pages.
menu_rebuild();
// Now, actually create the new nodes and remove the page manager pages.
foreach ($pages as $data) {
$page = $data['page'];
$handler = $data['handler'];
$display = $data['display'];
//print_r($page);
//print_r($handler);
//print_r($display);
// Create a new 'Landing page' node.
$node = entity_create('node', array('type' => 'panopoly_landing_page'));
$node->title = $display->title;
$node->path = array(
'pathauto' => FALSE,
'alias' => $page->path,
);
$node->uid = 1;
if ($page->menu['type'] == 'normal') {
$node->menu = array(
'enabled' => TRUE,
'link_title' => $page->menu['title'],
'menu_name' => $page->menu['name'],
);
}
//print_r($node);
entity_save('node', $node);
// Create an entry on 'panelizer_entity' which will point to the same
// Panels display.
$panelizer = (object)array(
'entity_type' => 'node',
'entity_id' => $node->nid,
'revision_id' => $node->vid,
'name' => 'node:panopoly_landing_page:default',
'view_mode' => 'page_manager',
// Point to the same Panels display.
'did' => $display->did,
// Copy configuration.
'css_id' => $handler->conf['css_id'],
'css_class' => $handler->conf['body_classes_to_add'],
'css' => $handler->conf['css'],
'pipeline' => $handler->conf['pipeline'],
'contexts' => $handler->conf['contexts'],
'relationships' => $handler->conf['relationships'],
// Even if this wasn't true on the Page Manager page, we want this value
// to make newly created Landing Pages.
'no_blocks' => 1,
// Some other defaults.
'title_element' => 'H2',
'link_to_entity' => 1,
'extra' => array(),
);
drupal_write_record('panelizer_entity', $panelizer);
// Finally, we can remove the Page Manager page and handler.
db_delete('page_manager_pages')
->condition('pid', $page->pid)
->execute();
db_delete('page_manager_handlers')
->condition('did', $handler->did)
->execute();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment