- Issue created by @larowlan
- π§πͺBelgium wim leers Ghent π§πͺπͺπΊ
How would
::asResponse()
then get access to all this other information?/** * Get the auto saved changes. */ public function get(): CacheableJsonResponse { $all = $this->autoSaveManager->getAllAutoSaveList(); $userIds = \array_column($all, 'owner'); $cache = new CacheableMetadata(); /** @var \Drupal\user\UserInterface[] $users */ $users = $this->entityTypeManager->getStorage('user')->loadMultiple($userIds); foreach ($users as $uid => $user) { $access = $user->access('view label', return_as_object: TRUE); $cache->addCacheableDependency($user); $cache->addCacheableDependency($access); if (!$access->isAllowed()) { unset($users[$uid]); } } // User display names depend on configuration. $cache->addCacheableDependency($this->configFactory->get('user.settings')); // Remove 'data' key because this will reduce the amount of data sent to the // client and back to the server. $all = \array_map(fn(array $item) => \array_diff_key($item, ['data' => '']), $all); $withUserDetails = \array_map(fn(array $item) => [ // @phpstan-ignore-next-line 'owner' => \array_key_exists($item['owner'], $users) ? [ 'name' => $users[$item['owner']]->getDisplayName(), 'avatar' => $this->buildAvatarUrl($users[$item['owner']]), 'uri' => $users[$item['owner']]->toUrl()->toString(), 'id' => $item['owner'], ] : [ 'name' => new TranslatableMarkup('User @uid', ['@uid' => $item['owner']]), 'avatar' => NULL, 'uri' => NULL, 'id' => $item['owner'], ], ] + $item, $all); return (new CacheableJsonResponse($withUserDetails))->addCacheableDependency($cache->addCacheTags([AutoSaveManager::CACHE_TAG])); }
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
I think we can close this now we have ::isEmpty
My main gripe was that we were checking $autosave->data === NULL outside of the AutoSave Data class which was leaking an implementation detail.
The special case of NULL is unfortunate but I can live with it if _only_ the class itself is aware of what it means.
With ::isEmpty that is now the case (and I fixed the other is null check when we added isEmpty).
So yep, closed duplicate on π Code Components should render with their auto-saved state(if any) when rendered in the XB UI Active which fixed that