Search code examples
phpdrupaldrupal-7drupal-modulesdrupal-theming

Enable all the themes during installation of module drupal 7


How can i update a table during the installation of a module in drupal 7? i used the following code . But it is not working

function mymodule_install() {
drupal_install_schema('template_config');
db_update('system')
 ->fields(array(   
'status' => 1,
))
->condtion('type','theme','=')
->execute();
}

What is wrong in this code. i want to enable all the themes on the time of installation of mymodule.


Solution

  • You shouldn't call drupal_install_schema() from a hook_install() in Drupal 7, the schema will automatically be installed when the module is. Other than that your code will definitely work but I think you'll need to clear the caches straight after. Your install function should probably look like this:

    function mymodule_install() {
      db_update('system')
        ->fields(array('status' => 1))
        ->condtion('type','theme','=')
        ->execute();
    
      cache_clear_all();
    }
    

    Also make sure you're actually uninstalling and reinstalling your module, not just disabling it and then re-enabling it (click the 'Uninstall' tab from the modules page when you've disabled the module).