public function UnpublishByKeywordNode::execute

Executes the plugin.

Overrides ExecutableInterface::execute

File

drupal/core/modules/node/lib/Drupal/node/Plugin/Action/UnpublishByKeywordNode.php, line 28
Contains \Drupal\node\Plugin\Action\UnpublishByKeywordNode.

Class

UnpublishByKeywordNode
Unpublishes a node containing certain keywords.

Namespace

Drupal\node\Plugin\Action

Code

public function execute($node = NULL) {
  foreach ($this->configuration['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;
      $node
        ->save();
      break;
    }
  }
}