public function AdminModeration::publish in moderated content bulk publish 8
Same name and namespace in other branches
- 2.0.x src/AdminModeration.php \Drupal\moderated_content_bulk_publish\AdminModeration::publish()
- 1.0.x src/AdminModeration.php \Drupal\moderated_content_bulk_publish\AdminModeration::publish()
Publish Latest Revision.
File
- src/
AdminModeration.php, line 92
Class
- AdminModeration
- A Helper Class to assist with the publishing and unpublishing bulk action.
Namespace
Drupal\moderated_content_bulk_publishCode
public function publish() {
$user = \Drupal::currentUser();
$allLanguages = AdminHelper::getAllEnabledLanguages();
foreach ($allLanguages as $langcode => $languageName) {
if ($this->entity
->hasTranslation($langcode)) {
\Drupal::logger('moderated_content_bulk_publish')
->notice(utf8_encode("Publish latest revision {$langcode} for " . $this->id . " in moderated_content_bulk_publish"));
$latest_revision = self::_latest_revision($this->entity
->id(), $vid, $langcode);
if (!$latest_revision === FALSE) {
$this->entity = $latest_revision;
}
$this->entity = $this->entity
->getTranslation($langcode);
$this->entity
->set('moderation_state', 'published');
if ($this->entity instanceof RevisionLogInterface) {
// $now = time();
$this->entity
->setRevisionCreationTime(\Drupal::time()
->getRequestTime());
$msg = 'Bulk operation publish revision ';
$this->entity
->setRevisionLogMessage($msg);
$current_uid = \Drupal::currentUser()
->id();
$this->entity
->setRevisionUserId($current_uid);
}
$this->entity
->setSyncing(TRUE);
$this->entity
->setRevisionTranslationAffected(TRUE);
if ($user
->hasPermission('moderated content bulk publish')) {
$this->entity
->save();
}
else {
\Drupal::logger('moderated_content_bulk_publish')
->notice(utf8_encode("Bulk publish not permitted, check permissions."));
}
}
}
return $this->entity;
}