private function ScheduledPublishCron::updateEntityField in Scheduled Publish 8.2
Same name and namespace in other branches
- 8.3 src/Service/ScheduledPublishCron.php \Drupal\scheduled_publish\Service\ScheduledPublishCron::updateEntityField()
Update scheduled publish fields
Parameters
\Drupal\Core\Entity\ContentEntityBase $entity:
string $scheduledField:
Throws
\Exception
1 call to ScheduledPublishCron::updateEntityField()
- ScheduledPublishCron::doUpdateFor in src/
Service/ ScheduledPublishCron.php - Run field update for specific entity type
File
- src/
Service/ ScheduledPublishCron.php, line 146
Class
- ScheduledPublishCron
- Class ScheduledPublishCron
Namespace
Drupal\scheduled_publish\ServiceCode
private function updateEntityField(ContentEntityBase $entity, string $scheduledField) : void {
/** @var FieldItemList $scheduledEntity */
$scheduledEntity = $entity
->get($scheduledField);
$scheduledValue = $scheduledEntity
->getValue();
if (empty($scheduledValue)) {
return;
}
$currentModerationState = $entity
->get('moderation_state')
->getValue()[0]['value'];
foreach ($scheduledValue as $key => $value) {
if ($currentModerationState === $value['moderation_state'] || $this
->getTimestampFromIso8601($value['value']) <= $this->dateTime
->getCurrentTime()) {
unset($scheduledValue[$key]);
$this
->updateEntity($entity, $value['moderation_state'], $scheduledField, $scheduledValue);
}
}
}