Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
28ec0755
Commit
28ec0755
authored
Oct 18, 2010
by
Dries
Browse files
- Patch
#731518
by Damien Tournoud, Dave Reid: allow alteration of token values.
parent
63c15e54
Changes
2
Hide whitespace changes
Inline
Side-by-side
includes/token.inc
View file @
28ec0755
...
...
@@ -152,17 +152,24 @@ function token_scan($text) {
* An associative array of replacement values, keyed by the original 'raw'
* tokens that were found in the source text. For example:
* $results['[node:title]'] = 'My new node';
*
* @see hook_tokens()
* @see hook_tokens_alter()
*/
function
token_generate
(
$type
,
array
$tokens
,
array
$data
=
array
(),
array
$options
=
array
())
{
$results
=
array
();
$options
+=
array
(
'sanitize'
=>
TRUE
);
$replacements
=
module_invoke_all
(
'tokens'
,
$type
,
$tokens
,
$data
,
$options
);
$result
=
module_invoke_all
(
'tokens'
,
$type
,
$tokens
,
$data
,
$options
);
foreach
(
$result
as
$original
=>
$replacement
)
{
$results
[
$original
]
=
$replacement
;
}
// Allow other modules to alter the replacements.
$context
=
array
(
'type'
=>
$type
,
'tokens'
=>
$tokens
,
'data'
=>
$data
,
'options'
=>
$options
,
);
drupal_alter
(
'tokens'
,
$replacements
,
$context
);
return
$re
sul
ts
;
return
$re
placemen
ts
;
}
/**
...
...
modules/system/system.api.php
View file @
28ec0755
...
...
@@ -3807,6 +3807,8 @@ function hook_username_alter(&$name, $account) {
* An associative array of replacement values, keyed by the original 'raw'
* tokens that were found in the source text. For example:
* $results['[node:title]'] = 'My new node';
*
* @see hook_tokens_alter()
*/
function
hook_tokens
(
$type
,
$tokens
,
array
$data
=
array
(),
array
$options
=
array
())
{
$url_options
=
array
(
'absolute'
=>
TRUE
);
...
...
@@ -3864,6 +3866,46 @@ function hook_tokens($type, $tokens, array $data = array(), array $options = arr
return
$replacements
;
}
/**
* Alter replacement values for placeholder tokens.
*
* @param $replacements
* An associative array of replacements returned by hook_tokens().
* @param $context
* The context in which hook_tokens() was called. An associative array with
* the following keys, which have the same meaning as the corresponding
* parameters of hook_tokens():
* - 'type'
* - 'tokens'
* - 'data'
* - 'options'
*
* @see hook_tokens()
*/
function
hook_tokens_alter
(
array
&
$replacements
,
array
$context
)
{
$options
=
$context
[
'options'
];
if
(
isset
(
$options
[
'language'
]))
{
$url_options
[
'language'
]
=
$options
[
'language'
];
$language_code
=
$options
[
'language'
]
->
language
;
}
else
{
$language_code
=
NULL
;
}
$sanitize
=
!
empty
(
$options
[
'sanitize'
]);
if
(
$context
[
'type'
]
==
'node'
&&
!
empty
(
$context
[
'data'
][
'node'
]))
{
$node
=
$context
[
'data'
][
'node'
];
// Alter the [node:title] token, and replace it with the rendered content
// of a field (field_title).
if
(
isset
(
$context
[
'tokens'
][
'title'
]))
{
$title
=
field_view_field
(
'node'
,
$node
,
'field_title'
,
'default'
,
$language_code
);
$replacements
[
$context
[
'tokens'
][
'title'
]]
=
drupal_render
(
$title
);
}
}
}
/**
* Provide metadata about available placeholder tokens and token types.
*
...
...
@@ -3913,34 +3955,6 @@ function hook_token_info() {
);
}
/**
* Alter batch information before a batch is processed.
*
* Called by batch_process() to allow modules to alter a batch before it is
* processed.
*
* @param $batch
* The associative array of batch information. See batch_set() for details on
* what this could contain.
*
* @see batch_set()
* @see batch_process()
*
* @ingroup batch
*/
function
hook_batch_alter
(
&
$batch
)
{
// If the current page request is inside the overlay, add ?render=overlay to
// the success callback URL, so that it appears correctly within the overlay.
if
(
overlay_get_mode
()
==
'child'
)
{
if
(
isset
(
$batch
[
'url_options'
][
'query'
]))
{
$batch
[
'url_options'
][
'query'
][
'render'
]
=
'overlay'
;
}
else
{
$batch
[
'url_options'
][
'query'
]
=
array
(
'render'
=>
'overlay'
);
}
}
}
/**
* Alter the metadata about available placeholder tokens and token types.
*
...
...
@@ -3968,6 +3982,33 @@ function hook_token_info_alter(&$data) {
);
}
/**
* Alter batch information before a batch is processed.
*
* Called by batch_process() to allow modules to alter a batch before it is
* processed.
*
* @param $batch
* The associative array of batch information. See batch_set() for details on
* what this could contain.
*
* @see batch_set()
* @see batch_process()
*
* @ingroup batch
*/
function
hook_batch_alter
(
&
$batch
)
{
// If the current page request is inside the overlay, add ?render=overlay to
// the success callback URL, so that it appears correctly within the overlay.
if
(
overlay_get_mode
()
==
'child'
)
{
if
(
isset
(
$batch
[
'url_options'
][
'query'
]))
{
$batch
[
'url_options'
][
'query'
][
'render'
]
=
'overlay'
;
}
else
{
$batch
[
'url_options'
][
'query'
]
=
array
(
'render'
=>
'overlay'
);
}
}
}
/**
* Provide information on Updaters (classes that can update Drupal).
...
...
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