We have a custom module in development, the purpose of which is to fetch the email addresses of the users who review content. Upon revisiting this module (after updating from Drupal-7.41 to Drupal-7.51) its hook_tokens()
implementation is no longer being called in the same way it was before.
I cannot understand why this functionality no longer works. I thought this was a proper implementation of these functions. It now no longer fires on nodes, but when an entity is on a node.
Why would hook_tokens()
not be called on a node? (The module is enabled, depends on tokens and workbench_access, both of which are enabled.)
Please forgive me if my question is framed inappropriately, I may have an inaccurate understanding of the hook function(s), but I've checked the API and haven't gained clarity. I know for a fact that this module worked earlier this year with Drupal-7.41, but I couldn't find any changes in the related API since that release.
function mymodule_token_info() {
$info = array();
$info['tokens']['node']['publisher_one'] = array(
'name' => t('Section Publisher One'),
'description' => t('Email address of sections primary publisher.'),
);
$info['tokens']['node']['publisher_two'] = array(
'name' => t('Section Publisher Two'),
'description' => t('Email address of sections secondary publisher.'),
);
return $info;
}
function mymodule_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'node' && !empty($data['node'])) {
print_r('inside if conditional');
$section_users = array();
$users = entity_load('user');
// Get the current Page's section ID (sID).
$sID = key(_workbench_access_get_node_section_names($data['node']));
$user_count = 0;
// Is a given user 1) assigned to the same section as the node and also
// of the role identified as the one to be notified.
// If so, their email address are acquired.
foreach($users as $user) {
$user_sections = _workbench_access_get_user_section_names($user);
if(array_key_exists($sID, $user_sections) && $user_count < 2){
$role_type = user_roles(TRUE)[variable_get('waemail_role', '0')];
if(in_array($role_type, $user->roles)){
if($user_count == 0){
$section_users['publisher_one'] = $user->mail;
$user_count++;
}
else if($user_count == 1){
$section_users['publisher_two'] = $user->mail;
$user_count++;
break;
}
}
}
}
// Assign the values aquired above to the tokens.
foreach ($tokens as $name => $original) {
switch ($name) {
case 'publisher_one':
if(!empty($section_users[$name]))
$replacements[$original] = $section_users[$name];
break;
case 'publisher_two':
if(!empty($section_users[$name]))
$replacements[$original] = $section_users[$name];
break;
}
}
} //end if($type == 'node'...
return $replacements;
}
$info = array(); $info['types']['node']['section-publishers'] = array( 'name' => t('Publishers for Access Section'), 'description' => t('Email addresses of the publishers of a given nodes section'), );
I also added that prefix to the other tokens so they are now: ['tokens']['node']['section-publishers']... However, it still doesn't appear to fire. Is that what you meant by adding a type array?poll_token_info()
does.