Skip to content

Commit 49e6d62

Browse files
committed
chore: support for instant preview based on user permissions
1 parent ae8eb45 commit 49e6d62

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

packages/composer/amazeelabs/silverback_autosave/src/Storage/AutosaveEntityFormDatabaseStorage.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function storeEntityAndFormState($form_id, $form_session_id, $entity_type
121121
/**
122122
* {@inheritdoc}
123123
*/
124-
public function getEntityAndFormState($form_id, $entity_type_id, $entity_id, $langcode, $uid, $form_session_id = NULL, $autosaved_timestamp = NULL) {
124+
public function getEntityAndFormState($form_id, $entity_type_id, $entity_id, $langcode, $uid = NULL, $form_session_id = NULL, $autosaved_timestamp = NULL) {
125125
$result = NULL;
126126
$query = $this->connection->select(static::AUTOSAVE_ENTITY_FORM_TABLE, 'cefa')
127127
->fields('cefa', ['entity', 'form_state', 'timestamp'])
@@ -134,8 +134,11 @@ public function getEntityAndFormState($form_id, $entity_type_id, $entity_id, $la
134134

135135
$query->condition('entity_type_id', $entity_type_id)
136136
->condition('entity_id', $entity_id)
137-
->condition('langcode', $langcode)
138-
->condition('uid', $uid);
137+
->condition('langcode', $langcode);
138+
139+
if (isset($uid)) {
140+
$query->condition('uid', $uid);
141+
}
139142

140143
if (isset($autosaved_timestamp)) {
141144
$query->condition('timestamp', $autosaved_timestamp);

packages/composer/amazeelabs/silverback_autosave/src/Storage/AutosaveEntityFormStorageInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function storeEntityAndFormState($form_id, $form_session_id, $entity_type
6363
* An array containing the entity object and the form state object, keyed
6464
* accordingly with 'entity' and 'form_state'.
6565
*/
66-
public function getEntityAndFormState($form_id, $entity_type_id, $entity_id, $langcode, $uid, $form_session_id = NULL, $timestamp = NULL);
66+
public function getEntityAndFormState($form_id, $entity_type_id, $entity_id, $langcode, $uid = NULL, $form_session_id = NULL, $timestamp = NULL);
6767

6868
/**
6969
* Retrieves the stored entity.

packages/composer/amazeelabs/silverback_gatsby/silverback_gatsby.permissions.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ trigger a gatsby build:
44
title: 'Trigger a Gatsby Build'
55
access publisher:
66
title: 'Access Publisher'
7+
fetch any autosaved entity:
8+
title: 'Fetch any autosaved entity'

packages/composer/amazeelabs/silverback_gatsby/src/Plugin/GraphQL/DataProducer/FetchEntity.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ public function resolve(
334334
// @todo Add DI to both.
335335
/** @var \Drupal\silverback_autosave\Storage\AutosaveEntityFormStorageInterface $autoSaveFormStorage */
336336
$autoSaveFormStorage = \Drupal::service('silverback_autosave.entity_form_storage');
337-
$autosaveUserId = \Drupal::currentUser()->id();
337+
$currentUser = \Drupal::currentUser();
338+
$autosaveUserId = $currentUser->hasPermission('fetch any autosaved entity') ? NULL : $currentUser->id();
338339

339340
/**
340341
* This causes leaked metadata error.

0 commit comments

Comments
 (0)