Open soniktrooth opened 7 years ago
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.
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!
@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.
Ah, you're totally right, I was on a call and just responding real quick-like. Hmmm....
@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.
@thiagodemellobueno you had thoughts today on an approach and/or whether this was still a thing that module needed to do. Care to elaborate?
@josh
Yeah, my thoughts are that this seems to be a relatively difficult and even then testy thing to solve with automation. As you mentioned D8 gets way more granular re: whats loaded in a given page at a given time.
If we shift our thinking re: this problem from a “feature” to a “workflow” or “best practices” approach, We can imagine that setting up a baseline set of includes to give us a “good baseline set of drupaly css and js includes”… is just another one of those tasks that we recognize and set aside time for like: “set up living style guide” … we could have “establish sites baseline asset includes in port and style guide”… then in the time it takes to see which things we want to include and populate an array/config in both style guide and prototype and were done.
Not exactly the most elegant solution, but if we’ve found anything it’s that solving this one has been consistently inelegant. This way it’s at least “part of the plan and not hard”
Thoughts?
On Dec 13, 2016, at 6:57 PM, Josh notifications@github.com wrote:
@thiagodemellobueno https://github.com/thiagodemellobueno you had thoughts today on an approach and/or whether this was still a thing that module needed to do. Care to elaborate?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kalamuna/kalastatic_dot_module/issues/22#issuecomment-266900451, or mute the thread https://github.com/notifications/unsubscribe-auth/AAE1dVhQNy1WGLxOHu7VQH76nGcymXU7ks5rHzDPgaJpZM4LA6LA.
@thiagodemellobueno fair enough—what do you envisage the workflow would look like? I'm assuming something like:
html.html
Is that what you were thinking?
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
kalastatic/css
, kalastatic/js
drupal_get_js()
anddrupal_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?