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;
}
* 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;
}
* @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();
}