Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal Module - Is it right

I haven't developed any modules for Drupal before and I guess really i'm just wanting some verification as to if this is "right" and I hope someone can help. Its been developed for Drupal 7, and is used to inject a javascript file into the footer of the page

sessioncam.module file:

<?php
/**
* @file
* The code below adds the sessioncam.js file in the footer section of your site
*/
?>

<?php
drupal_add_js(drupal_get_path('module', 'sessioncam') .'/sessioncam.js', array('type' => 'external', 'scope' => 'footer')) ;
?>

sessioncam.info file:

name = SessionCam
description = Module to inject the SessionCam recorder code
core = 7.x

Any help is appreciated

like image 433
Stefan Avatar asked Feb 28 '26 00:02

Stefan


1 Answers

That's not quite right. The call to drupal_add_js() shouldn't be in the global scope but in a hook function. If you want it added on every page hook_init() would be appropriate:

function sessioncam_init() {
  drupal_add_js(drupal_get_path('module', 'sessioncam') .'/sessioncam.js', array('type' => 'external', 'scope' => 'footer')) ;
}
like image 68
Clive Avatar answered Mar 02 '26 14:03

Clive