You are here

function breakpoints_breakpoints_group_reload_from_theme in Breakpoints 7

1 call to breakpoints_breakpoints_group_reload_from_theme()
breakpoints_breakpoints_group_reload in ./breakpoints.module
Reload the breakpoints as defined by the group.

File

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

Code

function breakpoints_breakpoints_group_reload_from_theme($theme_key) {

  // Clear caches so theme.info is fresh.
  system_rebuild_theme_data();
  drupal_theme_rebuild();
  $themes = list_themes();
  if (isset($themes[$theme_key]->info['breakpoints'])) {
    $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);

    // Build a group for each theme
    $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);
    return $breakpoint_group;
  }
}