This question is from code in uc_domain_access (Ubercart Domain Access)
There are these two token statements below in a module being ported to Drupal 7 that no one supports any longer in which the functions called have been replaced - but I do not know how to reformulate the code to the new functions
At my line 168 of the module is this one below which is part of a function that Implements hook_token_values() in D6 - returns an array => $values. (hook token values => http://www.drupalcontrib.org/api/drupal/contributions!token!token.api.php/function/hook_token_values/6 )
foreach (uc_store_token_values('global') as $token => $value) {
$values['order-' . $token] = $value;
}
AND at line 350
foreach (uc_store_token_values('global') as $token => $value) {
$vars[str_replace('-', '_', $token)] = $value;
}
The function "uc_store_token_values" is gone in D7 and in Drupal 7 is is NOW "uc_store_tokens"
AND the switch case token $type 'global' no longer exists - the new switch case is (would be) 'store' it appears, and returns an array now called $replacements - which otherwise is largely the same as the array $values
hook_token_values() in D6 is also gone and is NOW simply called as hook_tokens() in D7
I am not familiar with tokens. See also what has happened to others at https://www.drupal.org/documentation/modules/token/update/6/7
so if I change uc_store_token_values to uc_store_tokens and 'global' to 'store' - the error is " Missing argument 2 for uc_store_tokens(), called in . . . module on line 342 and defined in uc_store_tokens() (line 72 of . . . /uc_store.tokens.inc) which is => function uc_store_tokens($type, $tokens, $data = array(), $options = array()) { There entire function can be found as a uc_store_tokens search for Drupal 7)
So it appears argument 2 is "$tokens" of which there was no argument 2 and did not exist in uc_store_token_values in Drupal 6 and is apparently supposed to be an or the array of tokens to be replaced according to the Drupal 7 hook_tokens function API)
So the question is does anyone here know how are the two pieces of code above from 168 and 350 changed to comply with the new uc_store_tokens() function ?
答案 0 :(得分:0)
"用于提供令牌的钩子已被重命名。 hook_token_list()现在是hook_token_info(),而hook_token_values()现在是hook_tokens()。两个钩子的参数和返回值都比D6等值更改了。"这个来自=> https://www.drupal.org/documentation/modules/token/update/6/7
它还说" Drupal 6中的旧令牌名称和Drupal 7中新的可链式样式令牌之间目前没有升级路径。一些帮助函数正在写在token.module中。&#34 ;
显然,必须修改模块函数,并且可以在函数token_info文档中的https://drupal.stackexchange.com/questions/4930/how-to-programmatically-create-a-custom-token-in-a-module和https://drupal.stackexchange.com/questions/86136/formatting-output-of-token以及drupal.org找到一些示例代码