4

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.

  • 1
    Ultimately I think it hands off to drupal at github.com/civicrm/civicrm-core/blob/5.16.3/CRM/Utils/System/…. Is that what you're looking for? – Demerit Aug 29 '19 at 23:16
  • Good clue, thanks. But that looks like it's only handling full page output, and explicitly does not output anything for ajax/snippet output. – Alan Dixon Sep 3 '19 at 14:24
  • 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... – Demerit Sep 10 '19 at 0:49
  • Nevermind my problem is something else - something is mysteriously deleting one of my extension's settings. – Demerit Sep 10 '19 at 13:46
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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.