function UnpublishByKeywordNode::execute
Same name in other branches
- 9 core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php \Drupal\node\Plugin\Action\UnpublishByKeywordNode::execute()
- 8.9.x core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php \Drupal\node\Plugin\Action\UnpublishByKeywordNode::execute()
- 11.x core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php \Drupal\node\Plugin\Action\UnpublishByKeywordNode::execute()
Overrides ExecutableInterface::execute
File
-
core/
modules/ action/ src/ Plugin/ Action/ UnpublishByKeywordNode.php, line 27
Class
- UnpublishByKeywordNode
- Unpublishes a node containing certain keywords.
Namespace
Drupal\action\Plugin\ActionCode
public function execute($node = NULL) {
$elements = \Drupal::entityTypeManager()->getViewBuilder('node')
->view(clone $node);
$render = (string) \Drupal::service('renderer')->renderInIsolation($elements);
foreach ($this->configuration['keywords'] as $keyword) {
if (str_contains($render, $keyword) || str_contains($node->label(), $keyword)) {
$node->setUnpublished();
$node->save();
break;
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.