Currently, it seems like the module does not allow us to embed our own variables as implied in the Javascript configuration variabledocs. I was wondering if it would be viable to incorporate a hook to, in the meantime, provide us with this capability on the code level (simply by overwriting the initial array).

Usage:

/**
 * Implements hook_change_disqus_thread
 */
function foo_change_disqus_thread($disqus) {
  return array(
    'url' => 'http://www.example.com,
    'identifier' => 123,
    'title' => 'Hello World,
    'domain' => $disqus['domain'],
  );
}

Comments

pcho’s picture

StatusFileSize
new560 bytes

Corrected patch

skruf’s picture

This fails if more than one module implements the hook as module_invoke_all merges all the results recursively into one array. The array structure then changes and is incompatible with the rest of the code eg. $disqus['url'] is now an array rather than a string.

An alter hook would be more appropriate. Here is a patch for this.

slashrsm’s picture

Is there anything that can be achieved with this hook and cannot be achieved with hook_js_alter()?

hugronaphor’s picture

Issue summary: View changes

@slashrsm Your last question probably blocked everyone and they silently are using this patch.
Yes you can achieve the same things by hook_js_alter(), but it's easier, cleaner and better to do some Disqus variable re-write in a hook like this.

This is my choice: https://www.drupal.org/files/disqus-add_alter_hook_js_variables-1419562-...

damienmckenna’s picture

StatusFileSize
new1.19 KB
new1.19 KB

I think the API should be different.