class SetUnpublishingDate in Scheduler 2.x
Same name and namespace in other branches
- 8 scheduler_rules_integration/src/Plugin/RulesAction/SetUnpublishingDate.php \Drupal\scheduler_rules_integration\Plugin\RulesAction\SetUnpublishingDate
Provides a 'Set date for scheduled unpublishing' action.
Plugin annotation
@RulesAction(
id = "scheduler_set_unpublishing_date",
deriver = "Drupal\scheduler_rules_integration\Plugin\RulesAction\SchedulerRulesActionDeriver"
)
Hierarchy
- class \Drupal\scheduler_rules_integration\Plugin\RulesAction\SchedulerRulesActionBase extends \Drupal\rules\Core\RulesActionBase
- class \Drupal\scheduler_rules_integration\Plugin\RulesAction\SetUnpublishingDate
Expanded class hierarchy of SetUnpublishingDate
1 file declares its use of SetUnpublishingDate
- LegacySetUnpublishingDate.php in scheduler_rules_integration/
src/ Plugin/ RulesAction/ Legacy/ LegacySetUnpublishingDate.php
File
- scheduler_rules_integration/
src/ Plugin/ RulesAction/ SetUnpublishingDate.php, line 15
Namespace
Drupal\scheduler_rules_integration\Plugin\RulesActionView source
class SetUnpublishingDate extends SchedulerRulesActionBase {
/**
* Set the unpublish_on date on the entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be scheduled for unpublishing.
* @param int $date
* The date for unpublishing.
*/
public function doExecute(EntityInterface $entity, $date) {
$config = \Drupal::config('scheduler.settings');
$bundle_field = $entity
->getEntityType()
->get('entity_keys')['bundle'];
if ($entity->{$bundle_field}->entity
->getThirdPartySetting('scheduler', 'unpublish_enable', $config
->get('default_unpublish_enable'))) {
$entity
->set('unpublish_on', $date);
// When this action is invoked and it operates on the entity being edited
// then hook_entity_presave() will be executed automatically. But if this
// action is being used to schedule a different entity then we need to
// call the functions directly here.
scheduler_entity_presave($entity);
}
else {
// The action cannot be executed because the content type is not enabled
// for scheduled unpublishing.
$this
->notEnabledWarning($entity, 'unpublish');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SchedulerRulesActionBase:: |
protected | property | The entity type id. | |
SchedulerRulesActionBase:: |
public static | function | ||
SchedulerRulesActionBase:: |
public | function | Gives a warning when an entity is not enabled for Scheduler. | |
SchedulerRulesActionBase:: |
public | function | Constructs a SchedulerRulesActionBase object. | |
SetUnpublishingDate:: |
public | function | Set the unpublish_on date on the entity. |