Attach JavaScript and CSS assets when render entity using Views REST export

Solutions

We came up with a new module: Ajax Assets Plus.

The module provides a new render which collects all the necessary libraries during rendering. It results in an array:

return [
      'commands' ['An array with ajax commands for settings'],
      'content' => 'Rendered content(HTML)',
      'libraries' => 'all the needed assets grouped into libraries',
    ];

We had to to override the AjaxResponseAttachmentsProcessor and AssetResolver classes.

Also we implemented the hook_js_settings_build() to collect all the libraries on the page, as ajaxPageState does not contain all the dependencies.

Tags: Views / Ajax / Drupal 8

Similar questions

Can I attach a javascript function to a Drupal.behaviors javascript function?
I want to trigger another function any time Drupal.behaviors.MultiPage (found in field_group/multipage) changes page. It's part of this code: What I want to do is track anytime the user clicks the "Next" or "Previous" buttons - the code that triggers this is at the bottom of the snippet. Is there a way for me to bind an event handler to this functi...
How can I use webform to upload assets and create a project that can be assigned to different users
I am trying to put together a creative request form that a client would fill out. A studio manager would then follow up and assign to a project manager. I am using webform and rules as a starting point with the possibility of using Open Atrium.
How to load jQuery assets before blocks and regions
I need a jQuery script to load immediately before a certain block shows on my Drupal 8 front page. I'm trying to use the following but I get 'TypeError $ is not a function' in code inspector. Here's my script: The problem is the first line. In Drupal 8 what is the preferred way to write this script to accomplish what I want?
Link an image and add assets
I'm new to drupal, so this might be simple even if I can't find the solution. I have a custom module back_module with folders : From my templates/block-back.html.twig First issue: I want to print an image located in images/back.png I can't find the right url for the image <img src ="???" alt='backButton'/> I already find solutions to retrieve...
Attach a node to a menu link OR attach custom fields to menu links?
My client would like to add content to the top-level links in the main menu, in order to have "Featured" content that is displayed in the drop-down menu. They must be able to choose which piece of content will be shown, and which menu link it will be associated with. I figure I have two options: 1) Creating a "Featured in Menu" Content Type and add...
Views REST Export and Multi-Value Fields
I'm having trouble getting the Views REST export to work nicely with multi-value fields. I have an image field that can have multiple images. I have added the field to my REST export View, however all values are being output on the same line. Like this: What I would like to achieve is something like this: Is this possible? Perhaps using HOOK_views_...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.