0

Does anyone know a smarter way to load given settings from the THEMENAME.info file for the submit function only, than to create another "ghost"-form calling theme_get_setting() ? I would like to prevent the ghost form, since there is no input needed.

I only need some settings from the info file in the submit state.

1

You do not need to use a form to save these values. variable_get() and variable_set() functions will make it much easier to set the value and retrieve it.

However, if you still want to pass the information via the theme's .info file, you can do as follows:

Add your custom variables to the .info file

EX: my_awesome_theme.info file:

name = my_awesome_theme
core = 7.x
dragons_exists = 1
how_to_catch_a_dragon[] = "Be a dragonlord"
how_to_catch_a_dragon[] = "Tell him to surrender"

Drupal will ignore these extra stuff during normal module/theme scanning.

To get the value, you can it like this:

$data = drupal_parse_info_file('sites/all/themes/my_awesome_theme.info');

You can use functions like drupal_get_path() to get the correct path. $data will contain the values from the .info file. For example, the above .info file will yield

dpm() of the .info array

Note that drupal_parse_info_file() doc mentions that you should NOT use this method to store arbitrary data.

Parses Drupal module and theme .info files.

Info files are NOT for placing arbitrary theme and module-specific settings. Use variable_get() and variable_set() for that.

Update: If you only need to pass some variable from the form, and not necessarily from the .info file, just store the value in $form_state. As long as you don't overwrite some existing values, $form_state['values'] for example, it will work just fine.

Also, consider using a form element of #type => value. User will not see anything at all, not even a hidden form element. You can access this value from $form_state['values'] nevertheless.

  • 1
    wow! awesome. clear and understandable but with all needed info packed to get the whole picture. Awesome answer! Thank you very much Ayesh K! – nilsun Jul 5 '13 at 22:34
  • one drawback on both methods is that it causes many heat to get one,two values. I like your very detailed answer but I will stay with a small hidden form, which will load the only 1,2 values I need via default_value => theme_get_setting, since Drupal will look at info file if values does not exist in database. Then, I can pick up the values via $form_state['info'] on the submit level. – nilsun Jul 5 '13 at 22:58
  • Thanks @Nils. Please see the updated answer with some suggestions to pass values from the form. – AyeshK Jul 5 '13 at 23:28
  • Thanks Ayesh K. perfect. This is how we can leave the answer. Now it is up to the use case. Thank you very much. – nilsun Jul 6 '13 at 20:06

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.