Answers.Body: <p>I haven't found the answer to this question, but I can avoid it instead.</p>
  
  <p>These functions:</p>
  
  <pre><code>CRM_Core_Resources::singleton()-&gt;addScriptUrl()
  CRM_Core_Resources::singleton()-&gt;addScriptFile()
  CRM_Core_Resources::singleton()-&gt;addStyleFile()
  </code></pre>
  
  <p>all generate html that gets stored for later output, which is smart most of the time, so it can do some more processing (e.g. weeding out duplicates and/or compressing, whatever).</p>
  
  <p>But if you look in the CRM_Core_Resources object, you can instead use the internal functions to generate the html and then manually add it to the html region that's going to get output in the ajax call.</p>
  
  <p>Here's a patch that solved this for me, as an example.</p>
  
  <p><a href="https://github.com/iATSPayments/com.iatspayments.civicrm/commit/6441cd5dee2ee0163330cceb95b0ce4e3ae37fa8" rel="nofollow noreferrer">https://github.com/iATSPayments/com.iatspayments.civicrm/commit/6441cd5dee2ee0163330cceb95b0ce4e3ae37fa8</a></p>
  
  <p>Just adding js to the html being loaded doesn't always fire the functions that might get fired it was loaded with the original page, so you do have to pay attention to that.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-25T20:31:00.553Z
Answers.LastActivityDate: 2019-09-25T20:31:00.553Z
Answers.UserDisplayName: Alan Dixon
Body: <p>I'm trying to debug a Drupal/CiviCRM integration issue where js/css resources that are added in an extension are not getting output. I think it should get output as part of a form snippet that's getting loaded via ajax, and I can see that the code here: <a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Resources.php" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Resources.php</a> manages the code interface that allows extensions to add in their css and js, but I can't figure out at what point all the added js/css gets output. And I care because for the code I'm working with (webform civicrm), it isn't getting output. </p>
  
  <p>Presumably there's some core code somewhere that grabs the structured data via something like:</p>
  
  <pre><code>$resource = CRM_Core_Resources::singleton()
  </code></pre>
  
  <p>And then converts the $resource object into html for output?</p>
  
  <p>In the case I care about I want my css/js added to the end of a form that's being loaded via ajax, and the code seems to support this via the isAjaxMode method.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-08-29T23:16:29.530Z
Comments.Text: Ultimately I think it hands off to drupal at https://github.com/civicrm/civicrm-core/blob/5.16.3/CRM/Utils/System/Drupal.php#L246. Is that what you're looking for?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-03T14:24:20.417Z
Comments.Text: Good clue, thanks. But that looks like it's only handling full page output, and explicitly does not output anything for ajax/snippet output.
Comments.UserDisplayName: Alan Dixon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-10T00:49:53.873Z
Comments.Text: So I just noticed that some code I have that I was sure was working in 5.14 is no longer working. It's not exactly the same but is the same type of output, where I'm adding js the same way to what is effectively a snippet. I've just confirmed it works on 5.10 but not master. So I think something has changed since 5.14. Hmm...
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-10T13:46:24.233Z
Comments.Text: Nevermind my problem is something else - something is mysteriously deleting one of my extension's settings.
Comments.UserDisplayName: Demerit
Tags: <webform-civicrm><javascript>
Title: Where in the CiviCRM codebase do css and js resources get output for an AJAX url or snippet?
ThreadText: # Where in the CiviCRM codebase do css and js resources get output for an AJAX url or snippet?
  
  (Asked by: username_0 on 2019-08-29)
  
  I'm trying to debug a Drupal/CiviCRM integration issue where js/css resources that are added in an extension are not getting output. I think it should get output as part of a form snippet that's getting loaded via ajax, and I can see that the code here: https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Resources.php manages the code interface that allows extensions to add in their css and js, but I can't figure out at what point all the added js/css gets output. And I care because for the code I'm working with (webform civicrm), it isn't getting output. 
  Presumably there's some core code somewhere that grabs the structured data via something like:
  $resource = CRM_Core_Resources::singleton()
  
  And then converts the $resource object into html for output?
  In the case I care about I want my css/js added to the end of a form that's being loaded via ajax, and the code seems to support this via the isAjaxMode method.
  
  **Tags:** webform-civicrm, javascript
  
  > **Comments:**
  > **username_1**: Ultimately I think it hands off to drupal at https://github.com/civicrm/civicrm-core/blob/5.16.3/CRM/Utils/System/Drupal.php#L246. Is that what you're looking for?  
  > **username_0**: Good clue, thanks. But that looks like it's only handling full page output, and explicitly does not output anything for ajax/snippet output.  
  > **username_1**: So I just noticed that some code I have that I was sure was working in 5.14 is no longer working. It's not exactly the same but is the same type of output, where I'm adding js the same way to what is effectively a snippet. I've just confirmed it works on 5.10 but not master. So I think something has changed since 5.14. Hmm...  
  > **username_1**: Nevermind my problem is something else - something is mysteriously deleting one of my extension's settings.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-09-25. Score: 2
  
  I haven't found the answer to this question, but I can avoid it instead.
  These functions:
  CRM_Core_Resources::singleton()->addScriptUrl()
  CRM_Core_Resources::singleton()->addScriptFile()
  CRM_Core_Resources::singleton()->addStyleFile()
  
  all generate html that gets stored for later output, which is smart most of the time, so it can do some more processing (e.g. weeding out duplicates and/or compressing, whatever).
  But if you look in the CRM_Core_Resources object, you can instead use the internal functions to generate the html and then manually add it to the html region that's going to get output in the ajax call.
  Here's a patch that solved this for me, as an example.
  https://github.com/iATSPayments/com.iatspayments.civicrm/commit/6441cd5dee2ee0163330cceb95b0ce4e3ae37fa8
  Just adding js to the html being loaded doesn't always fire the functions that might get fired it was loaded with the original page, so you do have to pay attention to that.
  
  
  ---
  
  