diff --git a/scheduler.services.yml b/scheduler.services.yml index 6fc61c2..dd2b81a 100644 --- a/scheduler.services.yml +++ b/scheduler.services.yml @@ -11,6 +11,7 @@ services: - '@datetime.time' - '@entity_field.manager' - '@plugin.manager.scheduler' + - '@entity.definition_update_manager' logger.channel.scheduler: class: Drupal\Core\Logger\LoggerChannel diff --git a/src/SchedulerManager.php b/src/SchedulerManager.php index 5a0d593..78ac1b0 100644 --- a/src/SchedulerManager.php +++ b/src/SchedulerManager.php @@ -10,6 +10,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\FileStorage; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Entity\EntityChangedInterface; +use Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -91,6 +92,13 @@ class SchedulerManager { */ private $pluginManager; + /** + * The entity definition update manager. + * + * @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface + */ + private $entityDefinitionUpdateManager; + /** * Constructs a SchedulerManager object. */ @@ -102,7 +110,8 @@ class SchedulerManager { ContainerAwareEventDispatcher $eventDispatcher, TimeInterface $time, EntityFieldManagerInterface $entityFieldManager, - SchedulerPluginManager $pluginManager + SchedulerPluginManager $pluginManager, + EntityDefinitionUpdateManagerInterface $entityDefinitionUpdateManager ) { $this->dateFormatter = $dateFormatter; $this->logger = $logger; @@ -113,6 +122,7 @@ class SchedulerManager { $this->time = $time; $this->entityFieldManager = $entityFieldManager; $this->pluginManager = $pluginManager; + $this->entityDefinitionUpdateManager = $entityDefinitionUpdateManager; } /** @@ -243,6 +253,10 @@ class SchedulerManager { $ids = []; $scheduler_enabled_types = $this->getEnabledTypes($entityTypeId, $process); + $is_publish_on_translatable = $this->entityDefinitionUpdateManager + ->getFieldStorageDefinition('publish_on', $entityTypeId) + ->isTranslatable(); + if (!empty($scheduler_enabled_types)) { $query = $this->entityTypeManager->getStorage($entityTypeId)->getQuery() ->exists('publish_on') @@ -302,7 +316,13 @@ class SchedulerManager { // If the current translation does not have a publish on value, or it // is later than the date we are processing then move on to the next. - $publish_on = $entity->publish_on->value; + if (!$is_publish_on_translatable) { + // If not translatable, we retain value across all translations. + $publish_on = empty($publish_on) ? $entity->publish_on->value : $publish_on; + } + else { + $publish_on = $entity->publish_on->value; + } if (empty($publish_on) || $publish_on > $this->time->getRequestTime()) { continue; } @@ -468,6 +488,10 @@ class SchedulerManager { $ids = []; $scheduler_enabled_types = $this->getEnabledTypes($entityTypeId, $process); + $is_unpublish_on_translatable = $this->entityDefinitionUpdateManager + ->getFieldStorageDefinition('unpublish_on', $entityTypeId) + ->isTranslatable(); + if (!empty($scheduler_enabled_types)) { $query = $this->entityTypeManager->getStorage($entityTypeId)->getQuery() ->exists('unpublish_on') @@ -523,7 +547,13 @@ class SchedulerManager { // If the current translation does not have an unpublish-on value, or // it is later than the date we are processing then move to the next. - $unpublish_on = $entity->unpublish_on->value; + if (!$is_unpublish_on_translatable) { + // If not translatable, we retain value across all translations. + $unpublish_on = empty($unpublish_on) ? $entity->unpublish_on->value : $unpublish_on; + } + else { + $unpublish_on = $entity->unpublish_on->value; + } if (empty($unpublish_on) || $unpublish_on > $this->time->getRequestTime()) { continue; }