5

I tried two versions: 1.

$form_state = array();
form_load_include($form_state, 'inc', 'system', 'system.admin');
$form_state['values']['var'] = 'theme_settings';
$form_state['values']['logo_upload'] = file_save_upload('/path/to/logo.jpg');

drupal_form_submit('system_theme_settings_submit', $form_state);

2.

 variable_set('logo_path', '/path/to/my/uploaded/logo.jpg'); 

but none of them worked.

1 Answer 1

9

That setting is part of the theme settings variable; each setting is put in an array and that array is serialised as the value of the main theme settings variable.

You can set this value programmatically like so:

$theme_name = 'garland';  
$var_name = 'theme_' . $theme_name . '_settings';

$settings = variable_get($var_name, array());

$settings['logo_path'] = $new_path;

variable_set($var_name, $settings);
4
  • Clive can you comment a bit more about this? Your code is exactly what I'm looking for, but does it go in a module or theme-settings.php type file? Which hook would this go in?
    – blue928
    Jul 20, 2014 at 11:24
  • Couldn't say - whatever context you need to run the code in is where to put it. Might be in response to a form submission, node being updated, or any of the other dozens of events that Drupal raises. The code is context free so just run it wherever your use case tells you to
    – Clive
    Jul 20, 2014 at 11:29
  • @Clive Possible to do this via drush vset? Or do you have to use drush ev?
    – Beebee
    Aug 19, 2015 at 12:08
  • 1
    @blue928 A custom modules install-hook in an .install file would be a good place I think. There you could also reset your custom settings within an uninstall-hook later.
    – leymannx
    Jul 6, 2016 at 12:44

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.