Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
84e5d10b
Commit
84e5d10b
authored
Sep 11, 2010
by
Dries
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Patch
#627288
by sun, David_Rothstein: contextual links are not alterable.
parent
452e31f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
32 deletions
+88
-32
modules/contextual/contextual.api.php
modules/contextual/contextual.api.php
+41
-0
modules/contextual/contextual.module
modules/contextual/contextual.module
+45
-31
modules/system/system.api.php
modules/system/system.api.php
+2
-1
No files found.
modules/contextual/contextual.api.php
0 → 100644
View file @
84e5d10b
<?php
// $Id$
/**
* @file
* Hooks provided by Contextual module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Alter a contextual links element before it is rendered.
*
* This hook is invoked by contextual_pre_render_links(). The renderable array
* of #type 'contextual_links', containing the entire contextual links data that
* is passed in by reference. Further links may be added or existing links can
* be altered.
*
* @param $element
* A renderable array representing the contextual links.
* @param $items
* An associative array containing the original contextual link items, as
* generated by menu_contextual_links(), which were used to build
* $element['#links'].
*
* @see hook_menu_contextual_links_alter()
* @see contextual_pre_render_links()
* @see contextual_element_info()
*/
function
hook_contextual_links_view_alter
(
&
$element
,
$items
)
{
// Add another class to all contextual link lists to facilitate custom
// styling.
$element
[
'#attributes'
][
'class'
][]
=
'custom-class'
;
}
/**
* @} End of "addtogroup hooks".
*/
modules/contextual/contextual.module
View file @
84e5d10b
...
...
@@ -6,7 +6,6 @@
* Adds contextual links to perform actions related to elements on a page.
*/
/**
* Implements hook_help().
*/
...
...
@@ -56,10 +55,32 @@ function contextual_library() {
return
$libraries
;
}
/**
* Implements hook_element_info().
*/
function
contextual_element_info
()
{
$types
[
'contextual_links'
]
=
array
(
'#pre_render'
=>
array
(
'contextual_pre_render_links'
),
'#theme'
=>
'links__contextual'
,
'#links'
=>
array
(),
'#prefix'
=>
'<div class="contextual-links-wrapper">'
,
'#suffix'
=>
'</div>'
,
'#attributes'
=>
array
(
'class'
=>
array
(
'contextual-links'
),
),
'#attached'
=>
array
(
'library'
=>
array
(
array
(
'contextual'
,
'contextual-links'
),
),
),
);
return
$types
;
}
/**
* Template variable preprocessor for contextual links.
*
* @see contextual_links
_view
()
* @see contextual_
pre_render_
links()
*/
function
contextual_preprocess
(
&
$variables
,
$hook
)
{
static
$hooks
;
...
...
@@ -86,10 +107,14 @@ function contextual_preprocess(&$variables, $hook) {
}
if
(
isset
(
$element
)
&&
is_array
(
$element
)
&&
!
empty
(
$element
[
'#contextual_links'
]))
{
$variables
[
'title_suffix'
][
'contextual_links'
]
=
contextual_links_view
(
$element
);
if
(
!
empty
(
$variables
[
'title_suffix'
][
'contextual_links'
]))
{
$variables
[
'classes_array'
][]
=
'contextual-links-region'
;
}
// Initialize the template variable as a renderable array.
$variables
[
'title_suffix'
][
'contextual_links'
]
=
array
(
'#type'
=>
'contextual_links'
,
'#contextual_links'
=>
$element
[
'#contextual_links'
],
'#element'
=>
$element
,
);
// Mark this element as potentially having contextual links attached to it.
$variables
[
'classes_array'
][]
=
'contextual-links-region'
;
}
}
...
...
@@ -113,9 +138,7 @@ function contextual_preprocess(&$variables, $hook) {
*
* @see menu_contextual_links()
*/
function
contextual_links_view
(
$element
)
{
static
$destination
;
function
contextual_pre_render_links
(
$element
)
{
// Retrieve contextual menu links.
$items
=
array
();
foreach
(
$element
[
'#contextual_links'
]
as
$module
=>
$args
)
{
...
...
@@ -123,10 +146,6 @@ function contextual_links_view($element) {
}
// Transform contextual links into parameters suitable for theme_link().
if
(
!
isset
(
$destination
))
{
$destination
=
drupal_get_destination
();
}
$links
=
array
();
foreach
(
$items
as
$class
=>
$item
)
{
$class
=
drupal_html_class
(
$class
);
...
...
@@ -134,26 +153,21 @@ function contextual_links_view($element) {
'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
;
// @todo theme_links() should *really* use the same parameters as l().
$item
[
'localized_options'
]
+=
array
(
'query'
=>
array
());
$item
[
'localized_options'
][
'query'
]
+=
drupal_get_destination
();
$links
[
$class
]
+=
$item
[
'localized_options'
];
}
$build
=
array
();
if
(
$links
)
{
$build
=
array
(
'#prefix'
=>
'<div class="contextual-links-wrapper">'
,
'#suffix'
=>
'</div>'
,
'#theme'
=>
'links__contextual'
,
'#links'
=>
$links
,
'#attributes'
=>
array
(
'class'
=>
array
(
'contextual-links'
)),
'#attached'
=>
array
(
'library'
=>
array
(
array
(
'contextual'
,
'contextual-links'
)),
),
);
$element
[
'#links'
]
=
$links
;
// Allow modules to alter the renderable contextual links element.
drupal_alter
(
'contextual_links_view'
,
$element
,
$items
);
// If there are no links, tell drupal_render() to abort rendering.
if
(
empty
(
$element
[
'#links'
]))
{
$element
[
'#printed'
]
=
TRUE
;
}
return
$build
;
return
$element
;
}
modules/system/system.api.php
View file @
84e5d10b
...
...
@@ -1223,9 +1223,10 @@ function hook_menu_local_tasks_alter(&$data, $router_item, $root_path) {
* This is a normalized path, which means that an originally passed path of
* 'node/123' became 'node/%'.
*
* @see hook_contextual_links_view_alter()
* @see menu_contextual_links()
* @see hook_menu()
* @see
system
_preprocess()
* @see
contextual
_preprocess()
*/
function
hook_menu_contextual_links_alter
(
&
$links
,
$router_item
,
$root_path
)
{
// Add a link to all contextual links for nodes.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment