You are here

public function RemovePublishingDate::doExecute in Scheduler 2.x

Same name and namespace in other branches
  1. 8 scheduler_rules_integration/src/Plugin/RulesAction/RemovePublishingDate.php \Drupal\scheduler_rules_integration\Plugin\RulesAction\RemovePublishingDate::doExecute()

Remove the publish_on date from the entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity from which to remove the scheduled date.

File

scheduler_rules_integration/src/Plugin/RulesAction/RemovePublishingDate.php, line 23

Class

RemovePublishingDate
Provides a 'Remove date for scheduled publishing' action.

Namespace

Drupal\scheduler_rules_integration\Plugin\RulesAction

Code

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', 'publish_enable', $config
    ->get('default_publish_enable'))) {
    $entity
      ->set('publish_on', NULL);
    scheduler_entity_presave($entity);
  }
  else {

    // The action cannot be executed because the content type is not enabled
    // for scheduled publishing.
    $this
      ->notEnabledWarning($entity, 'publish');
  }
}