5

I'm creating a custom "glue" module for my site, and I want to define a path to another site as a global constant. Is there some drupal way to do it beyond putting a define() statement at the top of my module?

2 Answers 2

8

Use variable_get and variable_set.

2
  • But variable_get/set will be deprecated from Drupal 8. Is it still recommended to use them? Commented Nov 5, 2014 at 5:18
  • Upgrading Drupal 7 Variables to Drupal 8 Configuration - drupal.org/node/1667896
    – Nikit
    Commented Nov 6, 2014 at 5:30
3

If the glue module is really just for one site and it's no problem if it's hardcoded, by all means hardcode it.

A lot of constants are set in Drupal core's modules: http://api.drupal.org/api/constants/7

If you want a more flexible solution use a table with a single row and put it in there, and expose an interface to the admin to change that the value of that single row.

2
  • 3
    why worry about tables and single rows? use variable_set & variable_get which is exactly that :)
    – Rimian
    Commented Jan 26, 2010 at 1:18
  • In retrospect: the table with a single row is a bad alternative to variable_set and variable_get.
    – Niels Bom
    Commented Mar 24, 2014 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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