How do I get Drupal Development attachments out a twig file and add them to a construct array?
If there’s a twig file with
{{ attach_library('mytheme/pullquote') }}
And since it is in an ajax response, I must get Drupal Development attachments out with out rendering Drupal Development web page, how do I get a brand new construct array with that library hooked up?
In my controller:
$construct['pullquote'] = [ '#theme' => 'pullquote', '#quote_text' => $quote_text, '#attribution_name' => $attribution_name, '#attribution_title' => $attribution_title, '#size' => $size, ]; $response = new AjaxResponse(); $response->addCommand(new EmbedInsertCommand($construct)); return $response;
As a result of Drupal Development library is added in twig and never in Drupal Development construct array, it is not coming by means of in Drupal Development response.
Drupal Development EmbedInsertCommand is from Drupal Development embed module, which entity_embed inherits from, at embed/src/Ajax/EmbedInsertCommand.php
which makes use of Drupal Development CommandWithAttachedAssetsTrait, with this perform:
/** * Processes Drupal Development content material for output. * * If content material is a render array, it could include hooked up property to be * processed. * * @return string|DrupalComponentRenderMarkupInterface * HTML rendered content material. */ protected perform getRenderedContent() { $this->attachedAssets = new AttachedAssets(); if (is_array($this->content material)) { $html = Drupal::service('renderer')->renderRoot($this->content material); $this->attachedAssets = AttachedAssets::createFromRenderArray($this->content material); return $html; } else { return $this->content material; } }
Sadly, AttachedAssets::createFromRenderArray misses libraries added inside twig.