function answers_best_answer_node_view in Answers 7.4
Implements hook_node_view().
Adding the best answer widget or mark depending on user privileges.
File
- answers_best_answer/
answers_best_answer.module, line 315 - Support selection of 'Best Answers' for the 'Answers' module.
Code
function answers_best_answer_node_view($node, $view_mode = 'full') {
if ($view_mode == 'full' && $node->type == 'answers_answer') {
drupal_add_css(drupal_get_path('module', 'answers_best_answer') . '/css/answers_best_answer.css');
drupal_add_js(drupal_get_path('module', 'answers_best_answer') . '/js/answers_best_answer.js');
$flag = flag_get_flag('best_answer') or die('no "best_answer" flag defined');
global $user;
$node->content['best_answer'] = array(
'#type' => 'markup',
'#weight' => 100,
);
// If the user can set the flag, add the markup for it.
if (answers_best_answer_flag_access($flag, $node->nid, 'flag', $user)) {
$node->content['best_answer']['#markup'] = flag_create_link('best_answer', $node->nid);
}
elseif ($flag
->is_flagged($node->nid)) {
$node->content['best_answer']['#markup'] = '<div class="marked-best-answer">' . t('This one is the BEST !answer!', answers_translation()) . '</div>';
}
}
}