You are here

function breakpoints_themes_enabled in Breakpoints 7

Implements hook_themes_enabled(); Import breakpoints from all new enabled themes. Do not use breakpoints_breakpoints_group_reload_from_theme as is clears the cache.

3 calls to breakpoints_themes_enabled()
breakpoints_enable in ./breakpoints.module
Implements hook_enable(). Import breakpoints from all enabled themes.
breakpoints_flush_caches in ./breakpoints.module
Implements hook_flush_caches().
breakpoints_form_system_theme_settings_alter_submit in ./breakpoints.module

File

./breakpoints.module, line 61
Breakpoints @todo: provide button to reload breakpoints from theme

Code

function breakpoints_themes_enabled($theme_list, $rebuild_menu = TRUE) {
  $themes = list_themes();
  $updated = FALSE;
  $new_breakpoint_group = FALSE;
  foreach ($theme_list as $theme_key) {
    if (isset($themes[$theme_key]->info['breakpoints'])) {
      $updated = TRUE;
      $weight = 0;
      $theme_settings = $themes[$theme_key]->info['breakpoints'];
      $multipliers = isset($themes[$theme_key]->info['multipliers']) ? $themes[$theme_key]->info['multipliers'] : array();
      $settings = breakpoints_settings();
      $current_multipliers = drupal_map_assoc($settings->multipliers);
      $breakpoint_group = breakpoints_breakpoint_group_load($theme_key);
      if (!$breakpoint_group) {

        // Build a group for each theme
        $new_breakpoint_group = TRUE;
        $breakpoint_group = breakpoints_breakpoint_group_empty_object();
        $breakpoint_group->machine_name = $theme_key;
        $breakpoint_group->name = $themes[$theme_key]->info['name'];
        $breakpoint_group->type = BREAKPOINTS_SOURCE_TYPE_THEME;
      }
      foreach ($theme_settings as $name => $media_query) {
        $breakpoint = breakpoints_breakpoint_load($name, $theme_key, 'theme');
        if (!$breakpoint) {
          $breakpoint = breakpoints_breakpoint_empty_object();
          $breakpoint->name = $name;
          $breakpoint->source = $theme_key;
          $breakpoint->source_type = 'theme';
          $breakpoint->theme = '';
          $breakpoint->status = TRUE;
          $breakpoint->weight = $weight++;
          $breakpoint->machine_name = breakpoints_breakpoint_config_name($breakpoint);
        }
        $breakpoint->breakpoint = $media_query;
        $breakpoint->multipliers = isset($multipliers[$name]) ? drupal_map_assoc($multipliers[$name]) : array();
        $current_multipliers += drupal_map_assoc($breakpoint->multipliers);
        breakpoints_breakpoint_save($breakpoint);
        $breakpoint_group->breakpoints[] = $breakpoint->machine_name;
      }
      breakpoints_settings_save($current_multipliers);
      breakpoints_breakpoint_group_save($breakpoint_group);
      if ($new_breakpoint_group) {
        $message_text = 'The breakpoints from theme %theme are imported and <a href="@url">a new group is created</a>.';
      }
      else {
        $message_text = 'The breakpoints from theme %theme are imported and <a href="@url">an existing group was updated</a>.';
      }
      $message = t($message_text, array(
        '%theme' => $themes[$theme_key]->info['name'],
        '@url' => url('admin/config/media/breakpoints/groups/' . $theme_key),
      ));
      drupal_set_message($message, 'status');
    }
  }
  if ($rebuild_menu && $updated) {
    variable_set('menu_rebuild_needed', TRUE);
  }
}