- Issue created by @wim leers
- π§πͺBelgium wim leers Ghent π§πͺπͺπΊ
diff --git a/experience_builder.module b/experience_builder.module index 541a0f6c1..2d28db464 100644 --- a/experience_builder.module +++ b/experience_builder.module @@ -13,6 +13,7 @@ ini_set('assert.active', 1); use Drupal\Component\Serialization\Json; use Drupal\Core\Block\BlockManagerInterface; use Drupal\Core\Block\BlockPluginInterface; +use \Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Block\MainContentBlockPluginInterface; use Drupal\Core\Entity\EntityPublishedInterface; @@ -26,6 +27,7 @@ use Drupal\Core\Plugin\Discovery\YamlDiscovery; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; +use Drupal\experience_builder\AutoSave\AutoSaveManager; use Drupal\experience_builder\Entity\AssetLibrary; use Drupal\experience_builder\Entity\Component; use Drupal\experience_builder\Entity\JavaScriptComponent; @@ -784,7 +786,37 @@ function experience_builder_dialog_library_customize(string $admin_theme_name): * Implements hook_page_attachments(). */ function experience_builder_page_attachments(array &$page): void { - $page['#attached']['library'][] = 'experience_builder/asset_library.' . AssetLibrary::GLOBAL_ID; + // Load the auto-save/draft version of the global asset library in the XB UI, + // if it exists and is accessible for the current user. + if (str_starts_with(\Drupal::routeMatch()->getRouteName(), 'experience_builder.api.layout.')) { + $global_asset_library = AssetLibrary::load(AssetLibrary::GLOBAL_ID); + + $auto_saved_global_asset_library = NULL; + $auto_save_manager = \Drupal::service(AutoSaveManager::class); + assert($auto_save_manager instanceof AutoSaveManager); + $auto_save = $auto_save_manager->getAutoSaveData($global_asset_library); + if (!$auto_save->isEmpty()) { + \assert($auto_save->data !== NULL); + $auto_saved_global_asset_library = $global_asset_library->forAutoSavePreview($auto_save->data); + } + $page['#cache']['tags'][] = AutoSaveManager::CACHE_TAG; + + // If the current user is allowed to access draft versions of the global asset + // library and there is currently a draft, load the draft. + // @todo Update in https://www.drupal.org/project/experience_builder/issues/3508694 + $access = $global_asset_library->access('view', return_as_object: TRUE); + CacheableMetadata::createFromObject($access)->applyTo($page); + if ($auto_saved_global_asset_library !== NULL && $access->isAllowed()) { + $page['#attached']['library'][] = 'experience_builder/asset_library.' . AssetLibrary::GLOBAL_ID . '.draft'; + } + else { + $page['#attached']['library'][] = 'experience_builder/asset_library.' . AssetLibrary::GLOBAL_ID; + } + } + // Outside the XB UI, never load the draft. + else { + $page['#attached']['library'][] = 'experience_builder/asset_library.' . AssetLibrary::GLOBAL_ID; + } // Adds `track_navigation` library to all pages, to allow XB's "Back" link to know which URL to go back to. $page['#attached']['library'][] = 'experience_builder/track_navigation';
- Status changed to Needs work
3 days ago 12:59pm 7 May 2025 - π³π±Netherlands balintbrews Amsterdam, NL
This just became very relevant for a good experience after π Compile Tailwind CSS globally for code components Active lands.
- First commit to issue fork.
- πΊπΈUnited States tedbow Ithaca, NY, USA
2 e2e test fails, passed locally. PHPUnit tests passed
- π§πͺBelgium wim leers Ghent π§πͺπͺπΊ
- πΊπΈUnited States tedbow Ithaca, NY, USA
re #12 I created π Create loadAutoSave() helper function Active as follow-up for 2) and refactored for 1)
-
tedbow β
committed e0ae76fb on 0.x
Issue #3508937 by tedbow, wim leers: Global AssetLibrary should render...
-
tedbow β
committed e0ae76fb on 0.x