public static function AdminModeration::_latest_revision 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::_latest_revision()
- 1.0.x src/AdminModeration.php \Drupal\moderated_content_bulk_publish\AdminModeration::_latest_revision()
Get the latest revision.
1 call to AdminModeration::_latest_revision()
- AdminModeration::publish in src/
AdminModeration.php - Publish Latest Revision.
File
- src/
AdminModeration.php, line 132
Class
- AdminModeration
- A Helper Class to assist with the publishing and unpublishing bulk action.
Namespace
Drupal\moderated_content_bulk_publishCode
public static function _latest_revision($nid, &$vid, $langcode = NULL) {
// Can be removed once we move to Drupal >= 8.6.0 , currently on 8.5.0.
// See change record here: https://www.drupal.org/node/2942013 .
$lang = $langcode;
if (!isset($lang)) {
$lang = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
}
$latestRevisionResult = \Drupal::entityTypeManager()
->getStorage('node')
->getQuery()
->latestRevision()
->condition('nid', $nid, '=')
->execute();
if (count($latestRevisionResult)) {
$node_revision_id = key($latestRevisionResult);
if ($node_revision_id == $vid) {
// There is no pending revision, the current revision is the latest.
return FALSE;
}
$vid = $node_revision_id;
$latestRevision = \Drupal::entityTypeManager()
->getStorage('node')
->loadRevision($node_revision_id);
if ($latestRevision
->language()
->getId() != $lang && $latestRevision
->hasTranslation($lang)) {
$latestRevision = $latestRevision
->getTranslation($lang);
}
return $latestRevision;
}
return FALSE;
}