Commit fa5efed8 authored by Cottser's avatar Cottser

Issue #2528498 by Wim Leers, Jacine, mortendk: Only emit Quick Edit data-...

Issue #2528498 by Wim Leers, Jacine, mortendk: Only emit Quick Edit data- attributes when actually necessary
parent 348aa684
......@@ -124,6 +124,11 @@ function quickedit_preprocess_page_title(&$variables) {
* Implements hook_preprocess_HOOK() for field templates.
*/
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 */
$entity = $element['#object'];
......@@ -148,5 +153,10 @@ function quickedit_preprocess_field(&$variables) {
* Implements hook_entity_view_alter().
*/
function quickedit_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
$build['#cache']['contexts'][] = 'user.permissions';
if (!\Drupal::currentUser()->hasPermission('access in-place editing')) {
return;
}
$build['#attributes']['data-quickedit-entity-id'] = $entity->getEntityTypeId() . '/' . $entity->id();
}
......@@ -102,9 +102,10 @@ public function testUserWithoutPermission() {
$this->assertNoRaw('core/modules/quickedit/js/quickedit.js', 'Quick Edit library not loaded.');
$this->assertNoRaw('core/modules/quickedit/js/editors/formEditor.js', "'form' in-place editor not loaded.");
// HTML annotation must always exist (to not break the render cache).
$this->assertRaw('data-quickedit-entity-id="node/1"');
$this->assertRaw('data-quickedit-field-id="node/1/body/en/full"');
// HTML annotation does not exist for users without permission to in-place
// edit.
$this->assertNoRaw('data-quickedit-entity-id="node/1"');
$this->assertNoRaw('data-quickedit-field-id="node/1/body/en/full"');
// Retrieving the metadata should result in an empty 403 response.
$post = array('fields[0]' => 'node/1/body/en/full');
......@@ -519,6 +520,7 @@ public function testContentBlock() {
$this->drupalPlaceBlock('block_content:' . $block->uuid());
// Check that the data- attribute is present.
$this->drupalLogin($this->editorUser);
$this->drupalGet('');
$this->assertRaw('data-quickedit-entity-id="block_content/1"');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment