Skip to content
Snippets Groups Projects
Commit ceede1e9 authored by Jonathan Smith's avatar Jonathan Smith Committed by Jonathan Smith
Browse files

Issue #2651348 by jonathan1055: Add rules actions to publish and unpublish now

parent 30ece5e9
No related branches found
No related tags found
No related merge requests found
<?php
namespace Drupal\scheduler_rules_integration\Plugin\RulesAction;
use Drupal\rules\Core\RulesActionBase;
/**
* Provides a 'Publish the node immediately' action.
*
* @RulesAction(
* id = "scheduler_publish_now_action",
* label = @Translation("Publish the content immediately"),
* category = @Translation("Scheduler"),
* context = {
* "node" = @ContextDefinition("entity:node",
* label = @Translation("Node"),
* description = @Translation("The node to be published now"),
* ),
* }
* )
*/
class PublishNow extends RulesActionBase {
/**
* Set the node status to Published.
*
* @param \Drupal\node\Entity\Node $node
* The node object which will be set to Published.
*
* This action should really be provided by Rules or by Core, but it is not
* yet done (as of Aug 2016). Scheduler users need this action so we provide
* it here. It could be removed later when Rules or Core includes it.
*/
public function doExecute() {
$node = $this->getContextValue('node');
$node->setPublished(TRUE);
}
}
<?php
namespace Drupal\scheduler_rules_integration\Plugin\RulesAction;
use Drupal\rules\Core\RulesActionBase;
/**
* Provides an 'Unpublish the node immediately' action.
*
* @RulesAction(
* id = "scheduler_unpublish_now_action",
* label = @Translation("Unpublish the content immediately"),
* category = @Translation("Scheduler"),
* context = {
* "node" = @ContextDefinition("entity:node",
* label = @Translation("Node"),
* description = @Translation("The node to be unpublished now"),
* ),
* }
* )
*/
class UnpublishNow extends RulesActionBase {
/**
* Set the node status to Unpublished.
*
* @param \Drupal\node\Entity\Node $node
* The node object which will be set to Unpublished.
*
* This action should really be provided by Rules or by Core, but it is not
* yet done (as of Aug 2016). Scheduler users need this action so we provide
* it here. It could be removed later when Rules or Core includes it.
*/
public function doExecute() {
$node = $this->getContextValue('node');
$node->setPublished(FALSE);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment