i want to develop a module that has some pdf modelling functionality. I have an external script I want to use and some javascript. i wonder what is the best solution to get a module working from the drupal install routine.

1.) Do i have to add my external script to the drupal library...and remove it when my module is deinstalled? 2.) Can you recommend some good tutorials to get started with install scripts?

Any hints are welcome...



You should use the Libraries module - it allows integration with external libraries and scripts.
This is the correct way of adding libraries and using third party scripts in Drupal. This way several modules can use the same library and same sources, which is better from maintenance and organization perspective.

You can define a dependency in your custom module using the hook_libraries_info() and then include the library when you need it with libraries_load()`.

As an example, take a look at Colorbox to see how the hook is implemented there.

Check out also the Print module.

In your particular case, you will probably use TCPDF for generating PDFs, so you should define a library dependency like so:

 * Implements hook_libraries_info().
function YOUR_MODULE_libraries_info() {
  $libraries['tcpdf'] = array(
    'name' => 'TCPDF',
    'vendor' => 'http://www.tcpdf.org/',
    'download url' => 'http://sourceforge.net/projects/tcpdf/files/',
    'version callback' => 'YOUR_MODULE_tcpdf_version',
    'files' => array(
      'php' => array(

  return $libraries;

And when you need it, just call libraries_load():


Last thing - don't forget to add dependency for libraries in your module .info file.

  • i found the drupal.org/project/phpmailer example of @MohammedShameem a bit more enlightening, because the module activley creates a library... ;) Thanks a lot for the other explainations – Jurudocs Jan 22 '13 at 11:10

The install routine is many used if your module has any update or addition to be done to the database. The module install would have three functions commonly

  1. hook_install function is used to execute any function when the module is being installed. This would be a good place to add content to the table you would be creating.
  2. hook_uninstall This would be used to undo any changed you make to database during your installation process and if needed delete the contents from tables that was created by your module.
  3. hook_schema This function is used to create a tables or make changes to existing tables to make your module work.

Adding Javascript files and other css files should be either done in the .info file or by using the drupal_add_js and drupal_add_css functions with in your module.

There is a great module for all new module developers to refer to understand module creation and different aspects of the drupal internals - The Example Module

If you are looking to add external code into Drupal then you should look at libraries module which enables you to add other libraries into drupal and make it play well with drupal

  • Thanks for your answer...but thats what the hook install itself is saying...but what should i do with external php classes which have nothing to do with drupal...put it in the library when hook_install is called? Where do i have to put the phpfile itself...in the module and later add it to a library. What should a install script do with the external php class and its file? – Jurudocs Jan 22 '13 at 10:40
  • I have updated my answer. you should look at the libraries module and for an example of a module using libraries to include external php library you can take a look at drupal.org/project/phpmailer which makes use of the phpmailer – Mohammed Shameem Jan 22 '13 at 10:50

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.