Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Eric Rasmussen
UNL-CMS
Commits
4bfa9b4c
Commit
4bfa9b4c
authored
Oct 11, 2012
by
Eric Rasmussen
Browse files
[gh-482] Upgrade Token module to 7.x-1.4
parent
26746157
Changes
7
Hide whitespace changes
Inline
Side-by-side
sites/all/modules/token/tests/token_test.info
View file @
4bfa9b4c
...
...
@@ -5,9 +5,9 @@ core = 7.x
files
[]
=
token_test
.
module
hidden
=
TRUE
;
Information
added
by
drupal
.
org
packaging
script
on
2012
-
0
5
-
15
version
=
"7.x-1.
1
"
;
Information
added
by
drupal
.
org
packaging
script
on
2012
-
0
9
-
24
version
=
"7.x-1.
4
"
core
=
"7.x"
project
=
"token"
datestamp
=
"13
37115392
"
datestamp
=
"13
48497279
"
sites/all/modules/token/token.css
View file @
4bfa9b4c
...
...
@@ -4,6 +4,10 @@
margin-left
:
19px
;
}
.ui-dialog-content
.token-tree
{
margin-left
:
0
;
}
.token-tree
td
,
.token-tree
th
{
padding-top
:
0
;
padding-bottom
:
0
;
...
...
sites/all/modules/token/token.info
View file @
4bfa9b4c
...
...
@@ -7,9 +7,9 @@ files[] = token.tokens.inc
files[] = token.pages.inc
files[] = token.test
; Information added by drupal.org packaging script on 2012-0
5-15
version = "7.x-1.
1
"
; Information added by drupal.org packaging script on 2012-0
9-24
version = "7.x-1.
4
"
core = "7.x"
project = "token"
datestamp = "13
37115392
"
datestamp = "13
48497279
"
sites/all/modules/token/token.js
View file @
4bfa9b4c
...
...
@@ -9,6 +9,32 @@ Drupal.behaviors.tokenTree = {
}
};
Drupal
.
behaviors
.
tokenDialog
=
{
attach
:
function
(
context
,
settings
)
{
$
(
'
a.token-dialog
'
,
context
).
once
(
'
token-dialog
'
).
click
(
function
()
{
var
url
=
$
(
this
).
attr
(
'
href
'
);
var
dialog
=
$
(
'
<div style="display: none" class="loading">
'
+
Drupal
.
t
(
'
Loading token browser...
'
)
+
'
</div>
'
).
appendTo
(
'
body
'
);
dialog
.
dialog
({
title
:
$
(
this
).
attr
(
'
title
'
)
||
Drupal
.
t
(
'
Available tokens
'
),
width
:
700
,
close
:
function
(
event
,
ui
)
{
dialog
.
remove
();
}
});
// Load the token tree using AJAX.
dialog
.
load
(
url
,
{},
function
(
responseText
,
textStatus
,
XMLHttpRequest
)
{
dialog
.
removeClass
(
'
loading
'
);
}
);
// Prevent browser from following the link.
return
false
;
});
}
}
Drupal
.
behaviors
.
tokenInsert
=
{
attach
:
function
(
context
,
settings
)
{
// Keep track of which textfield was last selected/focused.
...
...
sites/all/modules/token/token.module
View file @
4bfa9b4c
...
...
@@ -11,7 +11,7 @@
define
(
'TOKEN_MAX_DEPTH'
,
9
);
/**
* Imp
e
lements hook_help().
* Implements hook_help().
*/
function
token_help
(
$path
,
$arg
)
{
if
(
$path
==
'admin/help#token'
)
{
...
...
@@ -73,6 +73,13 @@ function token_menu() {
'file' => 'token.pages.inc',
);*/
$items
[
'token/tree'
]
=
array
(
'page callback'
=>
'token_page_output_tree'
,
'access callback'
=>
TRUE
,
'type'
=>
MENU_CALLBACK
,
'file'
=>
'token.pages.inc'
,
);
// Devel token pages.
if
(
module_exists
(
'devel'
))
{
$items
[
'node/%node/devel/token'
]
=
array
(
...
...
@@ -146,16 +153,37 @@ function token_type_load($token_type) {
* Implements hook_theme().
*/
function
token_theme
()
{
return
array
(
'tree_table'
=>
array
(
'variables'
=>
array
(
'header'
=>
array
(),
'rows'
=>
array
(),
'attributes'
=>
array
(),
'empty'
=>
''
,
'caption'
=>
''
),
'file'
=>
'token.pages.inc'
,
$info
[
'tree_table'
]
=
array
(
'variables'
=>
array
(
'header'
=>
array
(),
'rows'
=>
array
(),
'attributes'
=>
array
(),
'empty'
=>
''
,
'caption'
=>
''
,
),
'token_tree'
=>
array
(
'variables'
=>
array
(
'token_types'
=>
array
(),
'global_types'
=>
TRUE
,
'click_insert'
=>
TRUE
,
'show_restricted'
=>
FALSE
,
'recursion_limit'
=>
3
),
'file'
=>
'token.pages.inc'
,
'file'
=>
'token.pages.inc'
,
);
$info
[
'token_tree'
]
=
array
(
'variables'
=>
array
(
'token_types'
=>
array
(),
'global_types'
=>
TRUE
,
'click_insert'
=>
TRUE
,
'show_restricted'
=>
FALSE
,
'recursion_limit'
=>
3
,
'dialog'
=>
FALSE
,
),
'file'
=>
'token.pages.inc'
,
);
$info
[
'token_tree_link'
]
=
array
(
'variables'
=>
array
(
'text'
=>
NULL
,
'options'
=>
array
(),
'dialog'
=>
TRUE
,
),
'file'
=>
'token.pages.inc'
,
);
return
$info
;
}
/**
...
...
@@ -175,6 +203,17 @@ function token_library() {
),
);
$libraries
[
'dialog'
]
=
array
(
'title'
=>
'Token dialog'
,
'version'
=>
'1.0'
,
'js'
=>
array
(
drupal_get_path
(
'module'
,
'token'
)
.
'/token.js'
=>
array
(),
),
'dependencies'
=>
array
(
array
(
'system'
,
'ui.dialog'
),
),
);
return
$libraries
;
}
...
...
@@ -274,14 +313,17 @@ function token_field_display_alter(&$display, $context) {
// use the default token formatter.
if
(
empty
(
$view_mode_settings
[
$context
[
'view_mode'
]][
'custom_settings'
]))
{
$field_type_info
=
field_info_field_types
(
$context
[
'field'
][
'type'
]);
if
(
!
empty
(
$field_type_info
[
'default_token_formatter'
]))
{
$display
[
'type'
]
=
$field_type_info
[
'default_token_formatter'
];
$formatter_info
=
field_info_formatter_types
(
$display
[
'type'
]);
$display
[
'settings'
]
=
isset
(
$formatter_info
[
'settings'
])
?
$formatter_info
[
'settings'
]
:
array
();
$display
[
'settings'
][
'label'
]
=
'hidden'
;
$display
[
'module'
]
=
$formatter_info
[
'module'
];
}
// If the field has specified a specific formatter to be used by default
// with tokens, use that, otherwise use the default formatter.
$formatter
=
!
empty
(
$field_type_info
[
'default_token_formatter'
])
?
$field_type_info
[
'default_token_formatter'
]
:
$field_type_info
[
'default_formatter'
];
// Now that we have a formatter, fill in all the settings.
$display
[
'type'
]
=
$formatter
;
$formatter_info
=
field_info_formatter_types
(
$formatter
);
$display
[
'settings'
]
=
isset
(
$formatter_info
[
'settings'
])
?
$formatter_info
[
'settings'
]
:
array
();
$display
[
'settings'
][
'label'
]
=
'hidden'
;
$display
[
'module'
]
=
$formatter_info
[
'module'
];
}
}
}
...
...
@@ -400,10 +442,12 @@ function token_entity_info_alter(&$info) {
* Adds missing token support for core modules.
*/
function
token_module_implements_alter
(
&
$implementations
,
$hook
)
{
if
(
$hook
==
'tokens'
||
$hook
==
'token_info'
)
{
module_load_include
(
'inc'
,
'token'
,
'token.tokens'
);
if
(
$hook
==
'tokens'
||
$hook
==
'token_info'
||
$hook
==
'token_info_alter'
||
$hook
==
'tokens_alter'
)
{
foreach
(
_token_core_supported_modules
()
as
$module
)
{
if
(
module_exists
(
$module
))
{
$implementations
[
$module
]
=
TRU
E
;
if
(
module_exists
(
$module
)
&&
function_exists
(
$module
.
'_'
.
$hook
)
)
{
$implementations
[
$module
]
=
FALS
E
;
}
}
// Move token.module to get included first since it is responsible for
...
...
@@ -674,7 +718,7 @@ function token_element_validate(&$element, &$form_state) {
}
// Check if the field defines specific token types.
if
(
!
empty
(
$element
[
'#token_types'
]))
{
if
(
isset
(
$element
[
'#token_types'
]))
{
$invalid_tokens
=
token_get_invalid_tokens_by_context
(
$tokens
,
$element
[
'#token_types'
]);
if
(
$invalid_tokens
)
{
form_error
(
$element
,
t
(
'The %element-title is using the following invalid tokens: @invalid-tokens.'
,
array
(
'%element-title'
=>
$title
,
'@invalid-tokens'
=>
implode
(
', '
,
$invalid_tokens
))));
...
...
sites/all/modules/token/token.pages.inc
View file @
4bfa9b4c
...
...
@@ -5,6 +5,63 @@
* User page callbacks for the token module.
*/
/**
* Theme a link to a token tree either as a regular link or a dialog.
*/
function
theme_token_tree_link
(
$variables
)
{
if
(
empty
(
$variables
[
'text'
]))
{
$variables
[
'text'
]
=
t
(
'Browse available tokens.'
);
}
if
(
!
empty
(
$variables
[
'dialog'
]))
{
drupal_add_library
(
'token'
,
'dialog'
);
$variables
[
'options'
][
'attributes'
][
'class'
][]
=
'token-dialog'
;
}
$info
=
token_theme
();
$variables
[
'options'
][
'query'
][
'options'
]
=
array_intersect_key
(
$variables
,
$info
[
'token_tree'
][
'variables'
]);
// We should never pass the dialog option to theme_token_tree(). It is only
// used for this function.
unset
(
$variables
[
'options'
][
'query'
][
'options'
][
'dialog'
]);
// Add a security token so that the tree page should only work when used
// when the dialog link is output with theme('token_tree_link').
$variables
[
'options'
][
'query'
][
'token'
]
=
drupal_get_token
(
'token-tree:'
.
serialize
(
$variables
[
'options'
][
'query'
][
'options'
]));
// Because PHP converts query strings with arrays into a different syntax on
// the next request, the options have to be encoded with JSON in the query
// string so that we can reliably decode it for token comparison.
$variables
[
'options'
][
'query'
][
'options'
]
=
drupal_json_encode
(
$variables
[
'options'
][
'query'
][
'options'
]);
// Set the token tree to open in a separate window.
$variables
[
'options'
][
'attributes'
]
+
array
(
'target'
=>
'_blank'
);
return
l
(
$variables
[
'text'
],
'token/tree'
,
$variables
[
'options'
]);
}
/**
* Page callback to output a token tree as an empty page.
*/
function
token_page_output_tree
()
{
$options
=
isset
(
$_GET
[
'options'
])
?
drupal_json_decode
(
$_GET
[
'options'
])
:
array
();
// Check the token against the serialized options to prevent random access to
// the token browser page.
if
(
!
isset
(
$_GET
[
'token'
])
||
!
drupal_valid_token
(
$_GET
[
'token'
],
'token-tree:'
.
serialize
(
$options
)))
{
return
MENU_ACCESS_DENIED
;
}
// Force the dialog option to be false so we're not creating a dialog within
// a dialog.
$options
[
'dialog'
]
=
FALSE
;
$output
=
theme
(
'token_tree'
,
$options
);
print
'<html><head><title></title>'
.
drupal_get_css
()
.
drupal_get_js
()
.
'</head>'
;
print
'<body class="token-tree">'
.
$output
.
'</body></html>'
;
drupal_exit
();
}
/**
* Theme a tree table.
*
...
...
@@ -32,6 +89,10 @@ function theme_tree_table($variables) {
* @ingroup themeable
*/
function
theme_token_tree
(
$variables
)
{
if
(
!
empty
(
$variables
[
'dialog'
]))
{
return
theme_token_tree_link
(
$variables
);
}
$token_types
=
$variables
[
'token_types'
];
$info
=
token_get_info
();
...
...
sites/all/modules/token/token.test
View file @
4bfa9b4c
...
...
@@ -1069,11 +1069,17 @@ class TokenBlockTestCase extends TokenTestHelper {
}
public
function
testBlockTitleTokens
()
{
$edit
[
'title'
]
=
'[
current-page:title] block title
'
;
$edit
[
'title'
]
=
'[
user:name]
'
;
$edit
[
'info'
]
=
'Test token title block'
;
$edit
[
'body[value]'
]
=
'This is the test token title block.'
;
$edit
[
'regions[bartik]'
]
=
'sidebar_first'
;
$this
->
drupalPost
(
'admin/structure/block/add'
,
$edit
,
'Save block'
);
// Ensure token validation is working on the block.
$this
->
assertText
(
'The Block title is using the following invalid tokens: [user:name].'
);
// Create the block for real now with a valid title.
$edit
[
'title'
]
=
'[current-page:title] block title'
;
$edit
[
'regions[bartik]'
]
=
'sidebar_first'
;
$this
->
drupalPost
(
NULL
,
$edit
,
'Save block'
);
$this
->
drupalGet
(
'node'
);
$this
->
assertText
(
'Welcome to '
.
variable_get
(
'site_name'
,
'Drupal'
)
.
' block title'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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