You are here

function breakpoints_admin_breakpoint_group_import_form_validate in Breakpoints 7

Validate a breakpoint group import.

File

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

Code

function breakpoints_admin_breakpoint_group_import_form_validate($form, &$form_state) {
  ctools_include('export');
  $code = $form_state['values']['import'];
  $group = ctools_export_crud_import('breakpoint_group', $code);
  if (!breakpoints_breakpoint_group_validate($group)) {
    form_set_error('import', t('Not a valid group object'));
    return;
  }
  if (breakpoints_breakpoint_group_name_exists($group->machine_name)) {
    form_set_error('import', t('A group with machine name %name already exists', array(
      '%name' => $group->machine_name,
    )));
    return;
  }
  foreach ($group->breakpoints as $key => $breakpoint) {

    // check if the breakpoint is a fully loaded object.
    if (is_array($breakpoint) || is_object($breakpoint)) {
      if (!breakpoints_breakpoint_validate($breakpoint)) {
        form_set_error('import', t('The breakpoint group contains an invalid breakpoint.'));
        return;
      }
    }
  }

  // Manually imported groups are the same as custom made groups.
  $group->type = BREAKPOINTS_SOURCE_TYPE_CUSTOM;
  form_set_value($form['import'], $group, $form_state);
}