function node_unpublish_by_keyword_action

Unpublishes a node containing certain keywords.

Parameters

Drupal\node\Node $node: A node entity to modify.

$context: Array of additional information about what triggered the action. Includes the following elements:

  • keywords: Array of keywords. If any keyword is present in the rendered node, the node's status flag is set to unpublished.

See also

node_unpublish_by_keyword_action_form()

node_unpublish_by_keyword_action_submit()

Related topics

File

drupal/core/modules/node/node.module, line 3700
The core module that allows content to be submitted to the site.

Code

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;
    }
  }
}