You are here

class SetPublishingDate in Scheduler 2.x

Same name and namespace in other branches
  1. 8 scheduler_rules_integration/src/Plugin/RulesAction/SetPublishingDate.php \Drupal\scheduler_rules_integration\Plugin\RulesAction\SetPublishingDate

Provides a 'Set date for scheduled publishing' action.

Plugin annotation


@RulesAction(
  id = "scheduler_set_publishing_date",
  deriver = "Drupal\scheduler_rules_integration\Plugin\RulesAction\SchedulerRulesActionDeriver"
)

Hierarchy

  • class \Drupal\scheduler_rules_integration\Plugin\RulesAction\SchedulerRulesActionBase extends \Drupal\rules\Core\RulesActionBase

Expanded class hierarchy of SetPublishingDate

1 file declares its use of SetPublishingDate
LegacySetPublishingDate.php in scheduler_rules_integration/src/Plugin/RulesAction/Legacy/LegacySetPublishingDate.php

File

scheduler_rules_integration/src/Plugin/RulesAction/SetPublishingDate.php, line 15

Namespace

Drupal\scheduler_rules_integration\Plugin\RulesAction
View source
class SetPublishingDate extends SchedulerRulesActionBase {

  /**
   * Set the publish_on date on the entity.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity to be scheduled for publishing.
   * @param int $date
   *   The date for publishing.
   */
  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', 'publish_enable', $config
      ->get('default_publish_enable'))) {
      $entity
        ->set('publish_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 publishing.
      $this
        ->notEnabledWarning($entity, 'publish');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SchedulerRulesActionBase::$entityTypeId protected property The entity type id.
SchedulerRulesActionBase::create public static function
SchedulerRulesActionBase::notEnabledWarning public function Gives a warning when an entity is not enabled for Scheduler.
SchedulerRulesActionBase::__construct public function Constructs a SchedulerRulesActionBase object.
SetPublishingDate::doExecute public function Set the publish_on date on the entity.