Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drupal assets #22

Open
soniktrooth opened this issue Dec 1, 2016 · 11 comments
Open

Drupal assets #22

soniktrooth opened this issue Dec 1, 2016 · 11 comments

Comments

@soniktrooth
Copy link
Contributor

drupal_get_js() and drupal_get_css() are the key to being able to generate the assets page, however these functions have disappeared in D8. I've had a dig but cannot work out what black spell to cast in order to evoke a similar reaction out of the beast. Any ideas @RobLoach or @derekderaps?

@soniktrooth
Copy link
Contributor Author

So I went down a big rabbit hole with this. I seem to be in the right general area but I can't work it out.

I found some interesting code in processAttachments() in HtmlResponseAttachentsProcessor.php and boiled it down to:

    $attached = $response->getAttachments();
    $assets = AttachedAssets::createFromRenderArray(['#attached' => $attached]);
    $css = AssetResolver::getCssAssets($assets);

But I don't know how to get a $response or even if I'm able to get one inside a Controller. I could be barking up the wrong tree, but these functions sound like they should do what we want.

@hawkeyetwolf
Copy link

In D7, I use the #attached property for FormAPI and render elements whenever possible. As a last resort you can attach to the page render element via hook_page_alter().

drupal_add_css() and _js() are a last resort. I can dig up documentation on that if you'd like.

Not sure about D8 though, I look forward to learning!

@soniktrooth
Copy link
Contributor Author

@derekderaps you're misunderstanding.

I'm calling drupal_GET_js() and drupal_GET_css() in D7 which returns rendered <script> and <style> tags. This is consumed by Kalastatic and stuck inside the styleguide/prototype <head></head> so that when we are styling things, we are taking into account the styling that Drupal will be adding to the page.

We need to get the same functionality for D8 but it seems a lot more complex. At the end of the day though there is SOMETHING that is rendering those tags in head so we just have to work out what and where so we can call it. Worst case is we have to load all the library.yml files and recreate it ourselves but I can't even work that out—all the OOP is turning my brain to goo. So undiscoverable.

@hawkeyetwolf
Copy link

Ah, you're totally right, I was on a call and just responding real quick-like. Hmmm....

@soniktrooth
Copy link
Contributor Author

@RobLoach now that we found a solution for #23 can you check this one out? We're not going to be able to style things properly in the prototype without this working.

@soniktrooth
Copy link
Contributor Author

@thiagodemellobueno you had thoughts today on an approach and/or whether this was still a thing that module needed to do. Care to elaborate?

@thiagodemellobueno
Copy link

thiagodemellobueno commented Dec 14, 2016 via email

@soniktrooth
Copy link
Contributor Author

@thiagodemellobueno fair enough—what do you envisage the workflow would look like? I'm assuming something like:

  • load a page (front page?)
  • copy the script and link tags from the head
  • paste into prototype html.html
  • paste into styleguide page template.

Is that what you were thinking?

@thiagodemellobueno
Copy link

thiagodemellobueno commented Dec 15, 2016

yeah,

or in kalastatic 2, populate kalastatic.yaml
@RobLoach hopped on the yaml hoverjetwagon

and populate 1d arrays, styles and scripts with paths that get printed in a loop in homepage.yaml and kstatic-kss-builder/index.twig

@RobLoach
Copy link
Contributor

  • Make KalaStatic bring in CSS/JS from Drupal 8
  • Make kalastatic_dot_module bring in CSS/JS from KSTAT

TODO

  1. Expose the JavaScript and CSS as HTML output kalastatic/css, kalastatic/js
  2. Have KSTAT include the CSS/JS in the Prototype
  3. Have KSTAT include the CSS/JS in the Styleguide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants