public function UnpublishByKeywordNode::execute in Drupal 8
Same name and namespace in other branches
- 9 core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php \Drupal\node\Plugin\Action\UnpublishByKeywordNode::execute()
- 10 core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php \Drupal\node\Plugin\Action\UnpublishByKeywordNode::execute()
Executes the plugin.
Overrides ExecutableInterface::execute
File
- core/
modules/ node/ src/ Plugin/ Action/ UnpublishByKeywordNode.php, line 24
Class
- UnpublishByKeywordNode
- Unpublishes a node containing certain keywords.
Namespace
Drupal\node\Plugin\ActionCode
public function execute($node = NULL) {
$elements = \Drupal::entityTypeManager()
->getViewBuilder('node')
->view(clone $node);
$render = \Drupal::service('renderer')
->render($elements);
foreach ($this->configuration['keywords'] as $keyword) {
if (strpos($render, $keyword) !== FALSE || strpos($node
->label(), $keyword) !== FALSE) {
$node
->setUnpublished();
$node
->save();
break;
}
}
}