function simplenews_node_view in Simplenews 7.2
Same name and namespace in other branches
- 8.2 simplenews.module \simplenews_node_view()
- 8 simplenews.module \simplenews_node_view()
- 7 simplenews.module \simplenews_node_view()
- 3.x simplenews.module \simplenews_node_view()
Implements hook_node_view().
File
- ./
simplenews.module, line 348 - Simplenews node handling, sent email, newsletter block and general hooks
Code
function simplenews_node_view($node, $view_mode) {
if (!simplenews_check_node_types($node->type)) {
return;
}
// Only do token replacements for view modes other than the our own email view
// modes. Token replacements for them will happen later on.
if (strpos($view_mode, 'email_') !== FALSE) {
return;
}
// Build up content, add as much as there is.
$context = array(
'node' => $node,
);
// If the current user is a subscriber, extend context.
if ($GLOBALS['user']->uid > 0 && ($subscriber = simplenews_subscriber_load_by_mail($GLOBALS['user']->mail))) {
$context['simplenews_subscriber'] = $subscriber;
}
// Loop over all render array elements.
foreach (element_children($node->content) as $key) {
$element =& $node->content[$key];
// Make sure this is a field.
if (!isset($element['#field_type'])) {
continue;
}
// Loop over all field values.
foreach (element_children($element) as $field_key) {
$item =& $element[$field_key];
// Only fields which result in simple markup elements are supported for
// token replacements for now.
if (isset($item['#markup'])) {
$item['#markup'] = token_replace($item['#markup'], $context, array());
}
}
}
}