You are here

class RemoveUnpublishingDate in Scheduler 2.x

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

Provides a 'Remove date for scheduled unpublishing' action.

Plugin annotation


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

Hierarchy

Expanded class hierarchy of RemoveUnpublishingDate

1 file declares its use of RemoveUnpublishingDate
LegacyRemoveUnpublishingDate.php in scheduler_rules_integration/src/Plugin/RulesAction/Legacy/LegacyRemoveUnpublishingDate.php

File

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

Namespace

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

  /**
   * Remove the unpublish_on date from the entity.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity from which to remove the scheduled date.
   */
  public function doExecute(EntityInterface $entity) {
    $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', NULL);
      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

Namesort descending Modifiers Type Description Overrides
RemoveUnpublishingDate::doExecute public function Remove the unpublish_on date from the entity.
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.