From 739fe58ef355b68448b7d428010ae6938084da56 Mon Sep 17 00:00:00 2001 From: Thomas Skovgaard Gielfeldt Date: Tue, 27 Mar 2012 01:12:10 +0200 Subject: [PATCH] Issue #1400884: Added hook_get_pane_links_alter() functionality allowing other modules to add/remove pane context menu links. Added "Edit mini panel". --- panels_mini/panels_mini.module | 14 +++ .../panels_renderer_editor.class.php | 95 ++++++++----------- 2 files changed, 54 insertions(+), 55 deletions(-) diff --git a/panels_mini/panels_mini.module b/panels_mini/panels_mini.module index 115a17b..8221ab8 100644 --- a/panels_mini/panels_mini.module +++ b/panels_mini/panels_mini.module @@ -127,6 +127,20 @@ function panels_mini_block_configure($delta = 0) { } /** + * Implements hook_get_pane_links_alter(). + */ +function panels_mini_get_pane_links_alter(&$links, $pane, $content_type) { + if ($pane->type == 'panels_mini') { + $links['top'][] = array( + 'title' => t('Edit mini panel'), + 'href' => url('admin/structure/mini-panels/list/' . $pane->subtype . '/edit/content', array('absolute' => TRUE)), + 'attributes' => array('target' => array('_blank')), + ); + } +} + + +/** * Statically store all used IDs to ensure all mini panels get a unique id. */ function panels_mini_get_id($name) { diff --git a/plugins/display_renderers/panels_renderer_editor.class.php b/plugins/display_renderers/panels_renderer_editor.class.php index 7aa9700..1c0785d 100644 --- a/plugins/display_renderers/panels_renderer_editor.class.php +++ b/plugins/display_renderers/panels_renderer_editor.class.php @@ -307,14 +307,14 @@ class panels_renderer_editor extends panels_renderer_standard { $links = array(); if (!empty($pane->shown)) { - $links[] = array( + $links['top'][] = array( 'title' => t('Disable this pane'), 'href' => $this->get_url('hide', $pane->pid), 'attributes' => array('class' => array('use-ajax')), ); } else { - $links[] = array( + $links['top'][] = array( 'title' => t('Enable this pane'), 'href' => $this->get_url('show', $pane->pid), 'attributes' => array('class' => array('use-ajax')), @@ -322,13 +322,13 @@ class panels_renderer_editor extends panels_renderer_standard { } if (isset($this->display->title_pane) && $this->display->title_pane == $pane->pid) { - $links['panels-set-title'] = array( + $links['top']['panels-set-title'] = array( 'title' => t('✓Panel title'), 'html' => TRUE, ); } else { - $links['panels-set-title'] = array( + $links['top']['panels-set-title'] = array( 'title' => t('Panel title'), 'href' => $this->get_url('panel-title', $pane->pid), 'attributes' => array('class' => array('use-ajax')), @@ -338,7 +338,7 @@ class panels_renderer_editor extends panels_renderer_standard { $subtype = ctools_content_get_subtype($content_type, $pane->subtype); if (ctools_content_editable($content_type, $subtype, $pane->configuration)) { - $links[] = array( + $links['top'][] = array( 'title' => isset($content_type['edit text']) ? $content_type['edit text'] : t('Settings'), 'href' => $this->get_url('edit-pane', $pane->pid), 'attributes' => array('class' => array('ctools-use-modal')), @@ -346,7 +346,7 @@ class panels_renderer_editor extends panels_renderer_standard { } if (user_access('administer advanced pane settings')) { - $links[] = array( + $links['top'][] = array( 'title' => t('CSS properties'), 'href' => $this->get_url('pane-css', $pane->pid), 'attributes' => array('class' => array('ctools-use-modal')), @@ -354,26 +354,10 @@ class panels_renderer_editor extends panels_renderer_standard { } if (user_access('administer panels styles')) { - $links[] = array( - 'title' => '
', - 'html' => TRUE, - ); - - $style_links = $this->get_style_links('pane', $pane->pid); - - $links[] = array( - 'title' => '' . t('Style') . '' . theme_links(array('links' => $style_links, 'attributes' => array(), 'heading' => array())), - 'html' => TRUE, - 'attributes' => array('class' => array('panels-sub-menu')), - ); + $links['style'] = $this->get_style_links('pane', $pane->pid); } if (user_access('administer pane access')) { - $links[] = array( - 'title' => '
', - 'html' => TRUE, - ); - $contexts = $this->display->context; // Make sure we have the logged in user context if (!isset($contexts['logged-in-user'])) { @@ -414,19 +398,10 @@ class panels_renderer_editor extends panels_renderer_standard { 'attributes' => array('class' => array('ctools-use-modal')), ); - $links[] = array( - 'title' => '' . t('Visibility rules') . '' . theme_links(array('links' => $visibility_links, 'attributes' => array(), 'heading' => array())), - 'html' => TRUE, - 'attributes' => array('class' => array('panels-sub-menu')), - ); + $links['visibility'] = $visibility_links; } if (user_access('use panels locks')) { - $links[] = array( - 'title' => '
', - 'html' => TRUE, - ); - $lock_type = !empty($pane->locks['type']) ? $pane->locks['type'] : 'none'; switch ($lock_type) { case 'immovable': @@ -451,19 +426,10 @@ class panels_renderer_editor extends panels_renderer_standard { 'attributes' => array('class' => array('ctools-use-modal')), ); - $links[] = array( - 'title' => '' . t('Locking') . '' . theme_links(array('links' => $lock_links, 'attributes' => array(), 'heading' => array())), - 'html' => TRUE, - 'attributes' => array('class' => array('panels-sub-menu')), - ); + $links['lock'] = $lock_links; } if (panels_get_caches() && user_access('use panels caching features')) { - $links[] = array( - 'title' => '
', - 'html' => TRUE, - ); - $method = isset($pane->cache['method']) ? $pane->cache['method'] : 0; $info = panels_get_cache($method); $cache_method = isset($info['title']) ? $info['title'] : t('No caching'); @@ -484,19 +450,10 @@ class panels_renderer_editor extends panels_renderer_standard { ); } - $links[] = array( - 'title' => '' . t('Caching') . '' . theme_links(array('links' => $cache_links, 'attributes' => array(), 'heading' => array())), - 'html' => TRUE, - 'attributes' => array('class' => array('panels-sub-menu')), - ); + $links['cache'] = $cache_links; } - $links[] = array( - 'title' => '
', - 'html' => TRUE, - ); - - $links[] = array( + $links['bottom'][] = array( 'title' => t('Remove'), 'href' => '#', 'attributes' => array( @@ -505,7 +462,35 @@ class panels_renderer_editor extends panels_renderer_standard { ), ); - return theme('ctools_dropdown', array('title' => theme('image', array('path' => ctools_image_path('icon-configure.png', 'panels'))), 'links' => $links, 'image' => TRUE)); + // Allow others to add/remove links from pane context menu. + // Grouped by 'top', 'style', 'visibility', 'lock', 'cache' and 'bottom' + drupal_alter('get_pane_links', $links, $pane, $content_type); + + $dropdown_links = $links['top']; + foreach (array( + 'style' => 'Style', + 'visibility' => 'Visibility rules', + 'lock' => 'Locking', + 'cache' => 'Caching' + ) as $category => $label) { + $dropdown_links[] = array( + 'title' => '
', + 'html' => TRUE, + ); + $dropdown_links[] = array( + 'title' => '' . t($label) . '' . theme_links(array('links' => $links[$category], 'attributes' => array(), 'heading' => array())), + 'html' => TRUE, + 'attributes' => array('class' => array('panels-sub-menu')), + ); + } + + $dropdown_links[] = array( + 'title' => '
', + 'html' => TRUE, + ); + $dropdown_links = array_merge($dropdown_links, $links['bottom']); + + return theme('ctools_dropdown', array('title' => theme('image', array('path' => ctools_image_path('icon-configure.png', 'panels'))), 'links' => $dropdown_links, 'image' => TRUE)); } // ----------------------------------------------------------------------- -- 1.7.0.4