function panopoly_widgets_update_7012 in Panopoly Widgets 7
Update 'Content item' widgets to reference NID rather than title.
File
- ./
panopoly_widgets.install, line 305 - An installation file for Panopoly Widgets
Code
function panopoly_widgets_update_7012() {
// Make sure the View for the 'Content item' widget gets updated.
features_revert(array(
'panopoly_widgets' => array(
'views_view',
),
));
views_invalidate_cache();
// Go through existing panes and update configuration.
// 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 = 'views_panes' AND subtype = 'panopoly_widgets_general_content-piece_of_content'");
$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 node using the View, set the NID and clear out the title.
$exposed =& $pane->configuration['exposed'];
$view = views_get_view('panopoly_widgets_general_content');
$view
->set_display('piece_of_content');
$view
->set_exposed_input($exposed);
$view
->pre_execute();
$view
->execute($view->current_display);
$view
->post_execute();
if (count($view->result) > 0) {
$exposed['nid'] = $view->result[0]->nid;
$exposed['title'] = '';
// Write back to the database.
drupal_write_record('panels_pane', $pane, array(
'pid',
));
}
}
}