You can edit existing mini panels, or click add to create a new one.

'); case 'admin/panels/panel-mini/add': return t('

Mini panels are the small variants of panel pages. Instead of pages, they define blocks.

'); } } /** * Implementation of hook_perm(). */ function panels_mini_perm() { return array('create mini panels', 'administer mini panels'); } /** * Implementation of hook_menu() */ function panels_mini_menu($may_cache) { if ($may_cache) { $access = user_access('create mini panels'); $items[] = array( 'path' => 'admin/panels/panel-mini', 'title' => t('Mini panels'), 'access' => $access, 'callback' => 'panels_mini_list_page', 'description' => t('Create and administer mini panels (panels exposed as blocks).'), ); $items[] = array( 'path' => 'admin/panels/panel-mini/list', 'title' => t('List'), 'access' => $access, 'callback' => 'panels_mini_list_page', 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/panels/panel-mini/add', 'title' => t('Add'), 'access' => $access, 'callback' => 'panels_mini_add_page', 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/panels/panel-mini/settings', 'title' => t('Settings'), 'access' => $access, 'callback' => 'panels_mini_settings', 'type' => MENU_LOCAL_TASK, ); } else { $result = db_query("SELECT * FROM {panels_mini}"); while ($panel_mini = db_fetch_object($result)) { panels_mini_menu_items($items, "admin/panels/panel-mini/$panel_mini->pid", $panel_mini); } } return $items; } function panels_mini_menu_items(&$items, $base, $panel_mini) { $access = user_access('administer mini panels'); if ($access) { $items[] = array( 'path' => $base, 'title' => t('Edit'), 'access' => $access, 'callback' => 'panels_mini_edit', 'callback arguments' => array($panel_mini->pid), 'weight' => -5, 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => $base .'/edit', 'title' => t('Edit'), 'access' => $access, 'callback' => 'panels_mini_edit', 'callback arguments' => array($panel_mini->pid), 'weight' => -5, 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => $base .'/edit/general', 'title' => t('General'), 'access' => $access, 'callback' => 'panels_mini_edit', 'callback arguments' => array($panel_mini->pid), 'weight' => -5, 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items[] = array( 'path' => $base .'/edit/layout', 'title' => t('Layout'), 'access' => $access, 'callback' => 'panels_mini_edit_layout', 'callback arguments' => array($panel_mini->pid), 'weight' => -3, 'type' => MENU_LOCAL_TASK, ); $display = panels_load_display($panel_mini->did); $layout = panels_get_layout($display->layout); if (!empty($layout['settings form'])) { $items[] = array( 'path' => $base .'/edit/settings', 'title' => t('Layout settings'), 'access' => $access, 'callback' => 'panels_mini_edit_layout_settings', 'callback arguments' => array($panel_mini->pid), 'weight' => -3, 'type' => MENU_LOCAL_TASK, ); } $items[] = array( 'path' => $base .'/edit/content', 'title' => t('Content'), 'access' => $access, 'callback' => 'panels_mini_edit_content', 'callback arguments' => array($panel_mini->pid), 'weight' => -1, 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => $base .'/delete', 'title' => t('Delete mini panel'), 'access' => user_access('create mini panels'), 'callback' => 'drupal_get_form', 'callback arguments' => array('panels_mini_delete_confirm', $panel_mini->pid), 'type' => MENU_CALLBACK, ); } } // --------------------------------------------------------------------------- // Mini panel administrative pages. /** * Settings for mini panels. */ function panels_mini_settings() { require_once drupal_get_path('module', 'panels') .'/panels_common.inc'; return drupal_get_form('panels_common_settings', 'panels_mini'); } /** * Provide a list of mini panels, with links to edit or delete them. */ function panels_mini_list_page() { $result = db_query("SELECT * FROM {panels_mini} ORDER BY title"); while ($panel_mini = db_fetch_object($result)) { $item = array(); $item[] = check_plain($panel_mini->title); $item[] = implode(' | ', array( l(t('Edit'), "admin/panels/panel-mini/$panel_mini->pid/edit"), l(t('Delete'), "admin/panels/panel-mini/$panel_mini->pid/delete"), )); $items[] = $item; } $header = array( t('Title'), t('Operations'), ); $output = theme('table', $header, $items); return $output; } /** * Provide a form to confirm deletion of a mini panel. */ function panels_mini_delete_confirm($panel_mini) { if (!is_object($panel_mini)) { $panel_mini = panels_mini_load($panel_mini); } $form['pid'] = array('#type' => 'value', '#value' => $panel_mini->pid); $form['did'] = array('#type' => 'value', '#value' => $panel_mini->did); return confirm_form($form, t('Are you sure you want to delete the mini panel "@title"?', array('@title' => $panel_mini->title)), $_GET['destination'] ? $_GET['destination'] : 'admin/panels/panel-mini', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } /** * Handle the submit button to delete a mini panel. */ function panels_mini_delete_confirm_submit($formid, $form) { if ($form['confirm']) { panels_mini_delete((object) $form); return 'admin/panels/panel-mini'; } } /** * Handle the add mini panel page. */ function panels_mini_add_page($layout = NULL) { $layouts = panels_get_layouts(); if ($layout === NULL) { foreach ($layouts as $id => $layout) { $output .= panels_print_layout_link($id, $layout, $_GET['q'] .'/'. $id); } return $output; } if (!$layouts[$layout]) { return drupal_not_found(); } $panel_mini->display = panels_new_display(); $panel_mini->display->layout = $layout; $panel_mini->pid = 'new'; $panel_mini->did = 'new'; return panels_mini_edit($panel_mini); } /** * Edit a mini panel. Called from both the add and edit points to provide for * common flow. */ function panels_mini_edit($panel_mini) { if (!is_object($panel_mini)) { $panel_mini = panels_mini_load($panel_mini); } drupal_set_title(check_plain($panel_mini->title)); return drupal_get_form('panels_mini_edit_form', $panel_mini); } /** * The form to edit the settings of a mini panel. */ function panels_mini_edit_form($panel_mini) { require_once drupal_get_path('module', 'panels') .'/panels_common.inc'; drupal_add_css(panels_get_path('css/panels_admin.css')); $form['pid'] = array( '#type' => 'value', '#value' => $panel_mini->pid, ); $form['panel_mini'] = array( '#type' => 'value', '#value' => $panel_mini ); $form['right'] = array( '#prefix' => '
', '#suffix' => '
', ); $form['left'] = array( '#prefix' => '
', '#suffix' => '
', ); $form['left']['settings'] = array( '#type' => 'fieldset', '#title' => t('Settings'), ); $form['left']['settings']['title'] = array( '#type' => 'textfield', '#size' => 24, '#default_value' => $panel_mini->title, '#title' => t('Mini panel title'), '#description' => t('The title for this mini panel. It can be overridden in the block configuration.'), ); // Add the "panel settings" section of the form and the accompanying submit // handler. $form['left'] += panels_common_panel_settings($panel_mini->display, 'panels_mini', 'mini panel'); $form['right']['layout'] = panels_common_get_layout_information($panel_mini); $label = ($panel_mini->pid == 'new') ? t('Next') : t('Save'); $form['submit'] = array( '#type' => 'submit', '#value' => $label, ); return $form; } /** * Process submission of the mini panel edit form. */ function panels_mini_edit_form_submit($form_id, $form_values) { $panel_mini = $form_values['panel_mini']; $panel_mini->title = $form_values['title']; $panel_mini->display->panel_settings = $form_values['panel_settings']; if ($panel_mini->pid == 'new') { panels_mini_save($panel_mini); // TODO: Why not use form_set_value()? $GLOBALS['form_values']['pid'] = $panel_mini->pid; return "admin/panels/panel-mini/$panel_mini->pid/edit/content"; } else { drupal_set_message(t('Your changes have been saved.')); panels_mini_save($panel_mini); } } /** * Pass through to the panels content editor. */ function panels_mini_edit_content($panel_mini) { if (!is_object($panel_mini)) { $panel_mini = panels_mini_load($panel_mini); } require_once drupal_get_path('module', 'panels') .'/panels_common.inc'; $content_types = panels_common_get_allowed_types('panels_mini'); // Print this with theme('page') so that blocks are disabled while editing a display. // This is important because negative margins in common block layouts (i.e, Garland) // messes up the drag & drop. drupal_set_title(check_plain($panel_mini->title)); print theme('page', panels_edit($panel_mini->display, "admin/panels/panel-mini/$panel_mini->pid/edit/content", $content_types), FALSE); } /** * Pass through to the panels layout editor. */ function panels_mini_edit_layout($panel_mini) { if (!is_object($panel_mini)) { $panel_mini = panels_mini_load($panel_mini); } drupal_set_title(check_plain($panel_mini->title)); return panels_edit_layout($panel_mini->display, t('Save'), "admin/panels/panel-mini/$panel_mini->pid/edit/layout"); } /** * Pass through to the panels layout settings editor. */ function panels_mini_edit_layout_settings($panel_mini) { if (!is_object($panel_mini)) { $panel_mini = panels_mini_load($panel_mini); } drupal_set_title(check_plain($panel_mini->title)); return panels_edit_layout_settings($panel_mini->display, t('Save'), "admin/panels/panel-mini/$panel_mini->pid/edit/settings"); } // --------------------------------------------------------------------------- // The actual panel_mini code. /** * Implementation of hook_block(). */ function panels_mini_block($op = 'list', $delta = 0, $edit = array()) { if ($op == 'list') { $blocks = array(); $result = db_query("SELECT * FROM {panels_mini} ORDER BY title"); while ($panel_mini = db_fetch_object($result)) { $blocks[$panel_mini->pid] = array( 'info' => t('Mini panel: "@title"', array('@title' => $panel_mini->title)), ); } return $blocks; } elseif ($op == 'view') { $panel_mini = panels_mini_load($delta); $block = array( 'subject' => $panel_mini->title, 'content' => panels_render_display($panel_mini->display) ); return $block; } } // --------------------------------------------------------------------------- // Database functions. /** * Load a mini panel. */ function panels_mini_load($pid) { static $cache = array(); if (!isset($cache[$pid])) { $panel_mini = db_fetch_object(db_query("SELECT * FROM {panels_mini} WHERE pid = %d", $pid)); $cache[$pid] = drupal_clone($panel_mini); if (!$cache[$pid]) { return; } $cache[$pid]->display = panels_load_display($cache[$pid]->did); $cache[$pid]->display->owner = drupal_clone($panel_mini); } return $cache[$pid]; } /** * Save a mini panel. */ function panels_mini_save(&$panel_mini) { $display = panels_save_display($panel_mini->display); if ($panel_mini->pid && $panel_mini->pid != 'new') { db_query( "UPDATE {panels_mini} SET " . "did = %d, " . "title = '%s' " . "WHERE pid = %d", $panel_mini->did, $panel_mini->title, $panel_mini->pid ); } else { $panel_mini->pid = db_next_id("{panels_mini}_pid"); db_query( "INSERT INTO {panels_mini} ( " . "pid, " . "did, " . "title " . ") " . "VALUES (" . "%d, " . "%d, " . "'%s'" . ")", $panel_mini->pid, $display->did, $panel_mini->title ); } return $panel_mini->pid; } /** * Delete a mini panel. */ function panels_mini_delete($panel_mini) { db_query("DELETE FROM {panels_mini} WHERE pid = %d", $panel_mini->pid); db_query("DELETE FROM {blocks} WHERE module = 'panels_mini' AND delta = %d", $panel_mini->pid); return panels_delete_display($panel_mini->did); } /** * Provide panels mini with its own category */ function panels_mini_panels_block_info($module, $delta, &$info) { $info['icon'] = 'icon_contrib_block.png'; $info['category'] = array(t('Mini panels'), -8); }