From 4278afa16bb46819975f95fe91021edcb852ca47 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sat, 17 Oct 2009 05:50:29 +0000 Subject: =?UTF-8?q?#473268=20by=20David=5FRothstein,=20sun,=20yoroy,=20G?= =?UTF-8?q?=C3=A1bor=20Hojtsy,=20cwgordon7,=20et=20al.:=20Allow=20contextu?= =?UTF-8?q?al=20editing=20of=20dang=20near=20everything=20on=20the=20page.?= =?UTF-8?q?=20Also=20adds=20a=20context=20system=20to=20menu=20local=20tas?= =?UTF-8?q?ks.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/system/system.module | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'modules/system/system.module') diff --git a/modules/system/system.module b/modules/system/system.module index 2bd5866ce..5c1abf524 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -3488,3 +3488,83 @@ function system_archiver_info() { function theme_confirm_form($variables) { return drupal_render_children($variables['form']); } + +/** + * Template variable preprocessor for contextual links. + */ +function system_preprocess(&$variables, $hook) { + static $hooks; + + if (!isset($hooks)) { + $hooks = theme_get_registry(); + } + + // Initialize contextual links template variable. + $variables['contextual_links'] = array(); + + // Determine the primary theme function argument. + $keys = array_keys($hooks[$hook]['arguments']); + $key = $keys[0]; + if (isset($variables[$key])) { + $element = $variables[$key]; + } + + if (isset($element) && is_array($element) && isset($element['#contextual_links'])) { + $variables['contextual_links'] = system_build_contextual_links($element); + if (!empty($variables['contextual_links'])) { + $variables['classes_array'][] = 'contextual-links-region'; + } + } +} + +/** + * Build a renderable array for contextual links. + * + * @param $element + * A renderable array containing a #contextual_links property. + * + * @return + * A renderable array representing contextual links. + */ +function system_build_contextual_links($element) { + static $destination; + + // Transform contextual links into parameters suitable for theme_link(). + $items = call_user_func_array('array_merge_recursive', $element['#contextual_links']); + $build = array(); + if (empty($items)) { + return $build; + } + + if (!isset($destination)) { + $destination = drupal_get_destination(); + } + + $links = array(); + foreach ($items as $class => $item) { + $class = drupal_html_class($class); + $links[$class] = array( + 'title' => $item['title'], + 'href' => $item['href'], + ); + // @todo theme_links() should *really* use the same parameters as l()... + if (!isset($item['localized_options']['query'])) { + $item['localized_options']['query'] = array(); + } + $item['localized_options']['query'] += $destination; + $links[$class] += $item['localized_options']; + } + if ($links) { + $build = array( + '#theme' => 'links', + '#links' => $links, + '#attributes' => array('class' => array('contextual-links')), + '#attached' => array( + 'js' => array('misc/contextual_links.js'), + 'css' => array('misc/contextual_links.css'), + ), + ); + } + return $build; +} + -- cgit v1.2.3