Unpublishes a node containing certain keywords.
Drupal\node\Node $node: A node entity to modify.
$context: Array of additional information about what triggered the action. Includes the following elements:
node_unpublish_by_keyword_action_form()
node_unpublish_by_keyword_action_submit()
function node_unpublish_by_keyword_action(Node $node, $context) {
foreach ($context['keywords'] as $keyword) {
$elements = node_view(clone $node);
if (strpos(drupal_render($elements), $keyword) !== FALSE || strpos($node
->label(), $keyword) !== FALSE) {
$node->status = NODE_NOT_PUBLISHED;
watchdog('action', 'Set @type %title to unpublished.', array(
'@type' => node_get_type_label($node),
'%title' => $node
->label(),
));
break;
}
}
}