Adding to the export asset store

Created on 13 June 2025, 22 days ago

How would I add assets to the single_content_sync.store inside an even subscriber?

I've made an ExportFieldEventSubscriber that preprocesses long text fields to convert inline image links from absolute to relative, so that they don't point to image in the old site when the content is migrated to the new.

It occurred to me that it would also be nice, at that point, to add the relevant asset to the collection you accumulate in your private temp store, so they'd also get exported, and be available for import in the destination file directories.

I feel like I'm close to making this work, but not quite there.

Any pointers?

πŸ’¬ Support request
Status

Active

Version

1.4

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States datawench

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

Comments & Activities

  • Issue created by @datawench
  • πŸ‡ΊπŸ‡¦Ukraine nginex

    Hi @datawench,

    If the relevant asset represents a file entity, you can load a file entity and export it with

    $embed_entities[] = $this->exporter->doExportToArray($file);
    

    then simply populate the field value with new embedded entities, so in results it looks like this.

    $value = $event->getFieldValue();
    $embed_entities = [];
    
    foreach ($value as &$item) {
      // Find and fetch file from the text $item['value'].
      ...
      
      // Export file.
      $embed_entities[] = $this->exporter->doExportToArray($file);
    
      foreach ($embed_entities as $embed_entity) {
        $item['embed_entities'][] = $embed_entity;
      }
    }
    
    $event->setFieldValue($value);
    

    If it's not a file entity, then pass file path to the private storage e.g.

    $assets = $this->privateTempStore->get('export.assets') ?? [];
    if (!in_array($filepath, $assets, TRUE)) {
      $assets[] = $filepath;
      $this->privateTempStore->set('export.assets', $assets);
    }
    

    where $this->privateTempStore is $container->get('single_content_sync.store')

    The import will automatically handle it.

  • πŸ‡ΊπŸ‡ΈUnited States datawench

    Beautiful. Thank you!

  • πŸ‡ΊπŸ‡ΈUnited States datawench
Production build 0.71.5 2024