Global AssetLibrary should render with its auto-saved state (if any) when rendered in the XB UI

Created on 25 February 2025, 2 months ago

Overview

We made sure to generate a experience_builder/asset_library.<name>.draft asset library in πŸ“Œ Code Components should render with their auto-saved state(if any) when rendered in the XB UI Active … but we never actually load it! πŸ˜…

IOW: we forgot to update experience_builder_page_attachments().

Proposed resolution

User interface changes

πŸ› Bug report
Status

Active

Version

0.0

Component

Theme builder

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • 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';
    
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Status changed to Needs work 3 days ago
  • πŸ‡³πŸ‡±Netherlands balintbrews Amsterdam, NL

    This just became very relevant for a good experience after πŸ“Œ Compile Tailwind CSS globally for code components Active lands.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Sample fix is in #2, tests still needed.

  • First commit to issue fork.
  • Merge request !1000Resolve #3508937 "Global asset draft" β†’ (Merged) created by tedbow
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    2 e2e test fails, passed locally. PHPUnit tests passed

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    RTBC'd with 2 caveats/requests: 1, 2.

    If not addressed here, we need a follow-up for especially the latter.

  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    re #12 I created πŸ› Create loadAutoSave() helper function Active as follow-up for 2) and refactored for 1)

  • Pipeline finished with Skipped
    1 day ago
    #492642
    • tedbow β†’ committed e0ae76fb on 0.x
      Issue #3508937 by tedbow, wim leers: Global AssetLibrary should render...
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    πŸŽ‰

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    πŸ₯³

Production build 0.71.5 2024