Paragraphs Editor
AssetGenerator.php
Go to the documentation of this file.
1 <?php
2 
4 
10 
11 /**
12  * Generates 'asset' models based on the compiled markup.
13  *
14  * The asset models will be loaded using the 'editor_assets' module, allowing
15  * the injection of Drupal asset libraries, including css, javascript, and
16  * javascript settings, into the editor.
17  */
19 
20  /**
21  * The asset processor to use for generating models.
22  *
23  * @var \Drupal\editor_assets\EditorAssetProcessorInterface
24  */
25  protected $assetProcessor;
26 
27  /**
28  * Creates an AssetGenerator.
29  *
30  * @param \Drupal\editor_assets\EditorAssetProcessorInterface $asset_processor
31  * The processor to use to convert bubbled libraries to importable asset
32  * models.
33  */
34  public function __construct(EditorAssetProcessorInterface $asset_processor) {
35  $this->assetProcessor = $asset_processor;
36  }
37 
38  /**
39  * {@inheritdoc}
40  */
41  public function id() {
42  return 'asset';
43  }
44 
45  /**
46  * {@inheritdoc}
47  */
48  public function complete(WidgetBinderData $data, WidgetBinderDataCompilerState $state, RenderContext $render_context, $markup) {
49  $attachments = $render_context->pop()->getAttachments();
50  $assets = $this->assetProcessor->processAttachments($attachments);
51 
52  foreach ($assets as $id => $asset) {
53  $asset['editorContextId'] = $state->getItemContext()->getAdditionalContext('editorContext');
54  $data->addModel('asset', $id, $asset);
55  }
56  }
57 
58 }
complete(WidgetBinderData $data, WidgetBinderDataCompilerState $state, RenderContext $render_context, $markup)
__construct(EditorAssetProcessorInterface $asset_processor)