'Export panels', 'access arguments' => array('use panels exporter'), 'page callback' => 'panels_export_export', 'description' => 'Export panels in bulk.', ); $items['admin/panels/export/results'] = array( 'access arguments' => array('use panels exporter'), 'page callback' => 'panels_export_export', 'type' => MENU_CALLBACK, ); return $items; } /** * Implementation of hook_theme() */ function panels_export_theme() { return array( 'panels_export_export_form' => array( 'arguments' => array('form' => NULL), ), ); } /** * Implementation of hook_perm(). */ function panels_export_perm() { return array('use panels exporter'); } /** * Page callback to export panels in bulk. */ function panels_export_export() { $exportables = array(); foreach (module_implements('panels_exportables') as $module) { $function = $module . '_panels_exportables'; $exportables[$module] = $function('list'); } if ($exportables) { $form_state = array( 're_render' => FALSE, 'no_redirect' => TRUE, 'exportables' => $exportables, ); $output = drupal_build_form('panels_export_export_form', $form_state); if (!$output) { $output = $form_state['output']; } return $output; } else { return t('There are no panels to be exported at this time.'); } } /** * Form to choose a group of panels to export. */ function panels_export_export_form(&$form_state) { foreach ($form_state['exportables'] as $module => $panels) { $form['modules'] = array( '#prefix' => '
', '#suffix' => '
', '#tree' => TRUE, ); $form['modules'][$module] = array( '#type' => 'checkboxes', '#options' => $panels, '#default_value' => array(), ); } $form['name'] = array( '#type' => 'textfield', '#title' => t('Module name'), '#description' => t('Enter the module name to export code to.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Export'), ); $form['#action'] = url('admin/panels/export/results'); $form['#exportables'] = $form_state['exportables']; return $form; } function theme_panels_export_export_form($form) { $files = module_rebuild_cache(); $exportables = $form['#exportables']; $output = ''; foreach ($exportables as $module => $panels) { $header = array(theme('table_select_header_cell'), $files[$module]->info['name']); $rows = array(); foreach ($panels as $name => $panel) { $title = $form['modules'][$module][$name]['#title']; unset($form['modules'][$module][$name]['#title']); $rows[] = array(drupal_render($form['modules'][$module][$name]), $title); } $output .= '
'; $output .= theme('table', $header, $rows); $output .= "
\n"; } drupal_add_css(panels_get_path('panels_export/panels_export.css')); $output .= drupal_render($form); return $output; } function panels_export_export_form_submit($form, &$form_state) { $code = ''; if (empty($form_state['values']['name'])) { $form_state['values']['name'] = 'foo'; } foreach ($form_state['values']['modules'] as $module => $panels) { $panels = array_filter($panels); if ($panels) { $code .= module_invoke($module, 'panels_exportables', 'export', $panels, $form_state['values']['name']) . "\n\n"; } } $lines = substr_count($code, "\n"); $element = array( '#type' => 'textarea', '#id' => 'export-textarea', '#name' => 'export-textarea', '#attributes' => array(), '#rows' => min($lines, 150), '#value' => $code, '#parents' => array(), ); $form_state['output'] = theme('textarea', $element); }