I have many sites in an installation that have many Panels pages. Many of them need a HTTP Response (404) variant added to them, which I would like to do programmatically.
Assume I have the page already via:
$page = page_manager_page_load($pageName);
Modifying something in the page is easy. Make the change then call
It seemed the easiest way to accomplish adding a variant was to take an exported variant and import it. This is what the clone function does.
Here is an exported variant:
$handler = new stdClass(); $handler->disabled = FALSE; /* Edit this to true to make a default handler disabled initially */ $handler->api_version = 1; $handler->name = 'page_bes_homepage__http_response_0ab6f1a9-9c98-459c-b4d3-10f63ddace56'; $handler->task = 'page'; $handler->subtask = ''; $handler->handler = 'http_response'; $handler->weight = 1; $handler->conf = array( 'title' => '404 Error', 'contexts' => array(), 'relationships' => array(), 'code' => '404', 'destination' => '', 'name' => '', );
It doesn't appear necessary to set the subtask or provide a new name since the
page_manager_handler_add_to_page() appears to handle that (though at first I set those myself; didn't help).
Attempting to add and save via:
page_manager_handler_add_to_page($page, $handler); page_manager_page_save($page);
doesn't work. Some code in page_manager.module had me think that the failure might might be because of ctools caching so I tried this:
page_manager_save_page_cache($page); page_manager_clear_page_cache($pageName); page_manager_page_save($page);
and that doesn't work either. Scouring the web for an example of this has not turned up anything in code snippets, tutorials or books and ctools doesn't provide this level of documentation.
How does one add a variant programmatically? Note that I do not want this in Features and I do not want this stored in code via the ctools api. I just want to run through a list of Panels pages programmatically and add a variant.