public function AdminModeration::archive in moderated content bulk publish 2.0.x
Same name and namespace in other branches
- 1.0.x src/AdminModeration.php \Drupal\moderated_content_bulk_publish\AdminModeration::archive()
Archive current revision.
File
- src/
AdminModeration.php, line 176
Class
- AdminModeration
- A Helper Class to assist with the publishing, archiving and unpublishing bulk action.
Namespace
Drupal\moderated_content_bulk_publishCode
public function archive() {
$user = \Drupal::currentUser();
$currentLang = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
$allLanguages = AdminHelper::getAllEnabledLanguages();
foreach ($allLanguages as $langcode => $languageName) {
if ($this->entity
->hasTranslation($langcode)) {
\Drupal::logger('moderated_content_bulk_publish')
->notice(utf8_encode("Archive {$langcode} for " . $this->id . " in moderated_content_bulk_publish"));
$this->entity = $this->entity
->getTranslation($langcode);
$this->entity
->set('moderation_state', 'archived');
if ($this->entity instanceof RevisionLogInterface) {
// $now = time();
$this->entity
->setRevisionCreationTime(\Drupal::time()
->getRequestTime());
$msg = 'Bulk operation create archived revision';
$this->entity
->setRevisionLogMessage($msg);
$current_uid = \Drupal::currentUser()
->id();
$this->entity
->setRevisionUserId($current_uid);
}
// $this->entity->setSyncing(TRUE); Removing and using shutdown call to complete save of alt lang.
$this->entity
->setRevisionTranslationAffected(TRUE);
if ($user
->hasPermission('moderated content bulk archive')) {
if ($langcode == $currentLang) {
$this->entity
->save();
}
else {
drupal_register_shutdown_function('Drupal\\moderated_content_bulk_publish\\AdminHelper::bulkPublishShutdown', $this->entity, $langcode, 'archived');
}
}
else {
\Drupal::logger('moderated_content_bulk_publish')
->notice(utf8_encode("Bulk archive not permitted, check permissions"));
}
}
}
return $this->entity;
}