X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fquickedit%2Fquickedit.module;h=1794f66f902f30f06ac6a1938f1a4cba85303c5f;hb=f3baf763d342a5f82576890e2a8111a5aaf139dc;hp=051b94834ae5e40e6e7ce48d702b5e71b68d103d;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/quickedit/quickedit.module b/web/core/modules/quickedit/quickedit.module index 051b94834..1794f66f9 100644 --- a/web/core/modules/quickedit/quickedit.module +++ b/web/core/modules/quickedit/quickedit.module @@ -11,6 +11,7 @@ * entities, enabling them for in-place editing. */ +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Routing\RouteMatchInterface; @@ -76,7 +77,7 @@ function quickedit_library_info_alter(&$libraries, $extension) { $theme = Drupal::config('system.theme')->get('admin'); // First let the base theme modify the library, then the actual theme. - $alter_library = function(&$library, $theme) use (&$alter_library) { + $alter_library = function (&$library, $theme) use (&$alter_library) { if (isset($theme) && $theme_path = drupal_get_path('theme', $theme)) { $info = system_get_info('theme', $theme); // Recurse to process base theme(s) first. @@ -128,14 +129,14 @@ function quickedit_preprocess_page_title(&$variables) { */ function quickedit_preprocess_field(&$variables) { $variables['#cache']['contexts'][] = 'user.permissions'; - if (!\Drupal::currentUser()->hasPermission('access in-place editing')) { - return; - } - $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') || !$entity->isLatestRevision()) { + return; + } + // Quick Edit module only supports view modes, not dynamically defined // "display options" (which \Drupal\Core\Field\FieldItemListInterface::view() // always names the "_custom" view mode). @@ -156,10 +157,32 @@ 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')) { + if (!\Drupal::currentUser()->hasPermission('access in-place editing') || !$entity->isLatestRevision()) { return; } $build['#attributes']['data-quickedit-entity-id'] = $entity->getEntityTypeId() . '/' . $entity->id(); } + +/** + * Check if a loaded entity is the latest revision. + * + * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * The entity to check. + * + * @return bool + * TRUE if the loaded entity is the latest revision, FALSE otherwise. + * + * @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) { + @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(); +}