You are here

function breakpoints_admin_breakpoint_group_import_form_submit in Breakpoints 7

Import breakpoint group.

File

./breakpoints.admin.inc, line 937
Breakpoints - admin settings

Code

function breakpoints_admin_breakpoint_group_import_form_submit($form, &$form_state) {
  $group = $form_state['values']['import'];
  foreach ($group->breakpoints as $key => $breakpoint) {

    // check if the breakpoint is a fully loaded object.
    if (is_array($breakpoint) || is_object($breakpoint)) {
      $breakpoint = (object) $breakpoint;

      // If the breakpoints exist, only overwrite the custom ones.
      if ($existing_breakpoint = breakpoints_breakpoint_load_by_fullkey($breakpoint->machine_name)) {
        if ($breakpoint->source_type == BREAKPOINTS_SOURCE_TYPE_CUSTOM) {
          $breakpoint = (object) array_merge((array) $existing_breakpoint, (array) $breakpoint);
          breakpoints_breakpoint_save($breakpoint);
        }
      }
      else {
        breakpoints_breakpoint_save($breakpoint);
      }
      $group->breakpoints[$key] = $breakpoint->machine_name;
    }
  }
  if (breakpoints_breakpoint_group_save($group)) {
    drupal_set_message(t('Group %group saved.', array(
      '%group' => $group->name,
    )));
    $form_state['redirect'] = 'admin/config/media/breakpoints/groups/' . $group->machine_name;
  }
  else {
    drupal_set_message(t('Something went wrong, we could not save the group', 'error'));
  }
}