Mercurial > hg > isophonics-drupal-site
comparison core/modules/quickedit/quickedit.module @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
128 * Implements hook_preprocess_HOOK() for field templates. | 128 * Implements hook_preprocess_HOOK() for field templates. |
129 */ | 129 */ |
130 function quickedit_preprocess_field(&$variables) { | 130 function quickedit_preprocess_field(&$variables) { |
131 $variables['#cache']['contexts'][] = 'user.permissions'; | 131 $variables['#cache']['contexts'][] = 'user.permissions'; |
132 $element = $variables['element']; | 132 $element = $variables['element']; |
133 /** @var $entity \Drupal\Core\Entity\EntityInterface */ | 133 /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ |
134 $entity = $element['#object']; | 134 $entity = $element['#object']; |
135 | 135 |
136 if (!\Drupal::currentUser()->hasPermission('access in-place editing') || !_quickedit_entity_is_latest_revision($entity)) { | 136 if (!\Drupal::currentUser()->hasPermission('access in-place editing') || !$entity->isLatestRevision()) { |
137 return; | 137 return; |
138 } | 138 } |
139 | 139 |
140 // Quick Edit module only supports view modes, not dynamically defined | 140 // Quick Edit module only supports view modes, not dynamically defined |
141 // "display options" (which \Drupal\Core\Field\FieldItemListInterface::view() | 141 // "display options" (which \Drupal\Core\Field\FieldItemListInterface::view() |
155 | 155 |
156 /** | 156 /** |
157 * Implements hook_entity_view_alter(). | 157 * Implements hook_entity_view_alter(). |
158 */ | 158 */ |
159 function quickedit_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) { | 159 function quickedit_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) { |
160 /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ | |
160 $build['#cache']['contexts'][] = 'user.permissions'; | 161 $build['#cache']['contexts'][] = 'user.permissions'; |
161 if (!\Drupal::currentUser()->hasPermission('access in-place editing') || !_quickedit_entity_is_latest_revision($entity)) { | 162 if (!\Drupal::currentUser()->hasPermission('access in-place editing') || !$entity->isLatestRevision()) { |
162 return; | 163 return; |
163 } | 164 } |
164 | 165 |
165 $build['#attributes']['data-quickedit-entity-id'] = $entity->getEntityTypeId() . '/' . $entity->id(); | 166 $build['#attributes']['data-quickedit-entity-id'] = $entity->getEntityTypeId() . '/' . $entity->id(); |
166 } | 167 } |
172 * The entity to check. | 173 * The entity to check. |
173 * | 174 * |
174 * @return bool | 175 * @return bool |
175 * TRUE if the loaded entity is the latest revision, FALSE otherwise. | 176 * TRUE if the loaded entity is the latest revision, FALSE otherwise. |
176 * | 177 * |
177 * @todo Remove this method once better support for pending revisions is added | 178 * @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use |
178 * to core https://www.drupal.org/node/2784201. | 179 * \Drupal\Core\Entity\RevisionableInterface::isLatestRevision() instead. |
180 * As internal API, _quickedit_entity_is_latest_revision() may also be removed | |
181 * in a minor release. | |
179 * | 182 * |
180 * @internal | 183 * @internal |
181 */ | 184 */ |
182 function _quickedit_entity_is_latest_revision(ContentEntityInterface $entity) { | 185 function _quickedit_entity_is_latest_revision(ContentEntityInterface $entity) { |
183 if (!$entity->getEntityType()->isRevisionable() || $entity->isNew()) { | 186 @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); |
184 return TRUE; | 187 return $entity->isLatestRevision(); |
185 } | |
186 | |
187 $latest_revision = \Drupal::entityTypeManager() | |
188 ->getStorage($entity->getEntityTypeId()) | |
189 ->getQuery() | |
190 ->latestRevision() | |
191 ->condition($entity->getEntityType()->getKey('id'), $entity->id()) | |
192 ->execute(); | |
193 | |
194 return !empty($latest_revision) && $entity->getLoadedRevisionId() == key($latest_revision) ? TRUE : FALSE; | |
195 } | 188 } |