rules-8.x-3.x-dev/src/Plugin/RulesAction/NodeMakeUnsticky.php
src/Plugin/RulesAction/NodeMakeUnsticky.php
<?php
namespace Drupal\rules\Plugin\RulesAction;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\node\NodeInterface;
use Drupal\rules\Context\ContextDefinition;
use Drupal\rules\Core\Attribute\RulesAction;
use Drupal\rules\Core\RulesActionBase;
/**
* Makes a content item not sticky.
*
* @RulesAction(
* id = "rules_node_make_unsticky",
* label = @Translation("Make selected content not sticky"),
* category = @Translation("Content"),
* context_definitions = {
* "node" = @ContextDefinition("entity:node",
* label = @Translation("Node"),
* description = @Translation("Specifies the content item to make not sticky."),
* assignment_restriction = "selector"
* ),
* }
* )
*/
#[RulesAction(
id: "rules_node_make_unsticky",
label: new TranslatableMarkup("Make selected content not sticky"),
category: new TranslatableMarkup("Content"),
context_definitions: [
"node" => new ContextDefinition(
data_type: "entity:node",
label: new TranslatableMarkup("Node"),
description: new TranslatableMarkup("Specifies the content item to make not sticky."),
assignment_restriction: "selector"
),
]
)]
class NodeMakeUnsticky extends RulesActionBase {
/**
* Executes the action with the given context.
*
* @param \Drupal\node\NodeInterface $node
* The node to modify.
*/
protected function doExecute(NodeInterface $node) {
$node->setSticky(NodeInterface::NOT_STICKY);
}
/**
* {@inheritdoc}
*/
public function autoSaveContext(): array {
// The node should be auto-saved after the execution.
return ['node'];
}
}
