Skip to content

Instantly share code, notes, and snippets.

@shadcn
Created September 2, 2014 19:46
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 shadcn/8b4c6e2404825c387450 to your computer and use it in GitHub Desktop.
Save shadcn/8b4c6e2404825c387450 to your computer and use it in GitHub Desktop.
Switch Panopoly Layouts to Radix Layouts.
/**
* Replace Panopoly layouts with Radix Layouts
* @param $plugin
* @param $info
*/
function radix_ctools_plugin_post_alter(&$plugin, &$info) {
// If Radix Layouts module is installed.
// Switch all Panopoly Panels layouts to Radix Layouts.
if (module_exists('radix_layouts')) {
$radix_layouts_path = drupal_get_path('module', 'radix_layouts');
if (($info['type'] == 'layouts') && ($plugin['module'] == 'panopoly_theme')) {
if (strpos($plugin['theme'], 'radix_') === FALSE) {
$radix_theme = 'radix_' . $plugin['theme'];
$plugin['theme'] = $plugin['name'] = $radix_theme;
$plugin['module'] = 'radix_layouts';
$plugin['path'] = $radix_layouts_path . '/plugins/layouts/' . $radix_theme;
$plugin['file'] = $radix_theme;
}
}
}
}
@mike-potter
Copy link

Here is the code I am using in OA2 right now:

function oa_radix_ctools_plugin_post_alter(&$plugin, &$info) {
if (module_exists('radix_layouts') && ($info['type'] == 'layouts') && ($plugin['module'] == 'panopoly_theme')) {
if (strpos($plugin['theme'], 'radix_') === FALSE) {
$new_name = 'radix_' . $plugin['theme'];
$path = drupal_get_path('module', 'radix_layouts') . '/plugins/layouts/' . $new_name;
if (file_exists($path)) {
$plugin['theme'] = $new_name;
$plugin['file'] = 'radix_' . $plugin['file'];
if (file_exists($path . '/radix-' . $plugin['icon'])) {
$plugin['path'] = $path;
$plugin['icon'] = 'radix-' . $plugin['icon'];
}
elseif (file_exists($path . '/radix_' . $plugin['icon'])) {
$plugin['path'] = $path;
$plugin['icon'] = 'radix_' . $plugin['icon'];
}
unset($plugin['css']);
}
}
}
}

sorry that is so ugly. The main point is to also handle the icon filename changes. It might also be nice if Radix Layouts standardized the icon names. I think one of the layouts uses _ instead of - in the icon filename. But also you should check if the corresponding radix layout actually exists before switching it. This helps handle the case of a Panopoly layout that isn't yet implemented in Radix. Using a "broken" Panopoly version is better than not having any layout at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment