function scheduler_node_view in Scheduler 8
Same name and namespace in other branches
- 7 scheduler.module \scheduler_node_view()
Implements hook_ENTITY_TYPE_view() for node entities.
File
- ./
scheduler.module, line 404 - Scheduler publishes and unpublishes nodes on dates specified by the user.
Code
function scheduler_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
// If the node is going to be unpublished, then add this information to the
// header for search engines. Only do this when the current page is the
// full-page view of the node.
// @see https://googleblog.blogspot.be/2007/07/robots-exclusion-protocol-now-with-even.html
if (!empty($node->unpublish_on->value) && node_is_page($node)) {
$unavailable_after = date(DATE_RFC850, $node->unpublish_on->value);
$build['#attached']['http_header'][] = [
'X-Robots-Tag',
'unavailable_after: ' . $unavailable_after,
];
}
}