Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / quickedit / quickedit.module
index ad08fc1e0df6af4d93cc26d06c0af415df901a1a..1794f66f902f30f06ac6a1938f1a4cba85303c5f 100644 (file)
@@ -130,10 +130,10 @@ function quickedit_preprocess_page_title(&$variables) {
 function quickedit_preprocess_field(&$variables) {
   $variables['#cache']['contexts'][] = 'user.permissions';
   $element = $variables['element'];
-  /** @var $entity \Drupal\Core\Entity\EntityInterface */
+  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
   $entity = $element['#object'];
 
-  if (!\Drupal::currentUser()->hasPermission('access in-place editing') || !_quickedit_entity_is_latest_revision($entity)) {
+  if (!\Drupal::currentUser()->hasPermission('access in-place editing') || !$entity->isLatestRevision()) {
     return;
   }
 
@@ -157,8 +157,9 @@ function quickedit_preprocess_field(&$variables) {
  * Implements hook_entity_view_alter().
  */
 function quickedit_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
+  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
   $build['#cache']['contexts'][] = 'user.permissions';
-  if (!\Drupal::currentUser()->hasPermission('access in-place editing') || !_quickedit_entity_is_latest_revision($entity)) {
+  if (!\Drupal::currentUser()->hasPermission('access in-place editing') || !$entity->isLatestRevision()) {
     return;
   }
 
@@ -174,22 +175,14 @@ function quickedit_entity_view_alter(&$build, EntityInterface $entity, EntityVie
  * @return bool
  *   TRUE if the loaded entity is the latest revision, FALSE otherwise.
  *
- * @todo Remove this method once better support for pending revisions is added
- * to core https://www.drupal.org/node/2784201.
+ * @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use
+ *   \Drupal\Core\Entity\RevisionableInterface::isLatestRevision() instead.
+ *   As internal API, _quickedit_entity_is_latest_revision() may also be removed
+ *   in a minor release.
  *
  * @internal
  */
 function _quickedit_entity_is_latest_revision(ContentEntityInterface $entity) {
-  if (!$entity->getEntityType()->isRevisionable() || $entity->isNew()) {
-    return TRUE;
-  }
-
-  $latest_revision = \Drupal::entityTypeManager()
-    ->getStorage($entity->getEntityTypeId())
-    ->getQuery()
-    ->latestRevision()
-    ->condition($entity->getEntityType()->getKey('id'), $entity->id())
-    ->execute();
-
-  return !empty($latest_revision) && $entity->getLoadedRevisionId() == key($latest_revision) ? TRUE : FALSE;
+  @trigger_error('_quickedit_entity_is_latest_revision() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\RevisionableInterface::isLatestRevision() instead. As internal API, _quickedit_entity_is_latest_revision() may also be removed in a minor release.', E_USER_DEPRECATED);
+  return $entity->isLatestRevision();
 }