Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm about to write a custom module dealing with chemical hazards symbols. It's basically a 300-item dictionary of simple objects: a symbol, its description (around 100 chars) and in some cases a supplementary short information.

I'm still undecided whether I'd make my module a text filter, field or entity, but regardless (I think) of the way I choose, I'm clueless about what would be the Drupal way to install this simple dictionary: as a PHP variable or a database table?

My guess would be that storing it as PHP variable would not burden the momenry too much, would provide quick lookup access and would save database queries. Would there be any benefit to choose the table option?

Edit 1: What is limiting me in using taxonomy here is that some terms would have to be supplemented by a piece of information on a binding/instance level. For example there would be a symbol (term) P0123: Store in temperatures below %1 C/ %2 F or P2345: Wash %1 thoroughly after handling. For each node referencing that term there should be a possibility to add the precise values that might be different per node. That is the reason I have been thinking of making it a text filter that would parse line:

P0123,10,50 (<- term with supplementary contextual values, %1 and %2)
P2345,en:hands|de:Hande|es:manos (<- i18n-savvy contextual string)
P3456 (<- term without additional info)

I have already filed a feature request for the Relation module, to provide labelling of relationships on instance level. We'll see if the authors consider it as worth implementing for a wider public. For now I'm trying to find a swift workaround.

share|improve this question

3 Answers 3

up vote 0 down vote accepted

If you were to use a PHP variable, you would need code that (for example) in hook_init() initializes that global variable, and that code would be executed at every page request.

If you were to use a Drupal variable, you could initialize it during the installation of your custom module (via variable_set()). You would still have the problem of having the content of those Drupal variables loaded in memory every time Drupal bootstraps, which includes also the case Drupal is answering to an AJAX request. This should be avoided, especially if those data are necessary just on specific pages.

The only alternative you have is creating a database table when your custom module is installed.
With Drupal 7, that means to just implement hook_schema(), and put that function in the .install file of your module. With Drupal 6, that means to implement hook_schema(), but also hook_install() with code similar to the following one.

function mymodule_install() {
  // Create tables.
  drupal_install_schema('mymodule');
}
share|improve this answer
    
Thanks for a thorough answer. –  Artur Jan 13 '13 at 18:26

In D7 I would make a Taxonomy out of such data. Just create a new taxonomy called Chemical Dictionary. Taxonomies already have:

  • a title
  • a description field

You just need to add a custom field for the image(s) using the Field UI. You could easily import these things from CSV or a remote database table using the Migrate module if your comfortable with code.

Taxonomy terms are stored in a database table by default in drupal, they are already entities.

While typically used for tagging things, you dont have to use it that way.

share|improve this answer
    
I have edited my question to provide more information that show why terms would be problematic. –  Artur Jan 13 '13 at 12:52

I would go with a database table. This would allow you to easily integrate it with the views module too. The hook you want to do it is hook_schema. http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_schema/7

share|improve this answer
    
I'm not sure I will have to provide View-based browsing of the symbols, but this is a very good point to have in mind. Thanks! –  Artur Jan 13 '13 at 12:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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