You are here

function panels_flexible_settings_validate in Panels 6.2

Same name and namespace in other branches
  1. 5.2 layouts/flexible.inc \panels_flexible_settings_validate()
1 string reference to 'panels_flexible_settings_validate'
panels_flexible_panels_layouts in layouts/flexible/flexible.inc
Implementation of hook_panels_layouts()

File

layouts/flexible/flexible.inc, line 205

Code

function panels_flexible_settings_validate($values, $form, $display, $layout, $settings) {
  if (empty($settings)) {
    $settings = panels_flexible_default_panels();
  }
  if ($values['rows'] < 1) {
    form_error($form['rows'], t('Rows must be a positive integer.'));
    return;
  }

  // Validate that percentages add up to the stated maximum.
  if ($values['width_type'] == '%') {
    for ($row = 1; $row <= intval($values['rows']); $row++) {

      // This takes into account whether or even had a previous setting here.
      if ($settings['rows'] >= $row) {
        if ($values["row_{$row}"]['columns'] < 1) {
          form_error($form["row_{$row}"]['columns'], t('Columns must be a positive integer.'));
          return;
        }
        $total = 0;
        for ($col = 1; $col <= intval($values["row_{$row}"]["columns"]); $col++) {
          $total += $values["row_{$row}"]["width_{$col}"];
        }
        if ($total != $values['percent_width']) {
          form_error($form["row_{$row}"]['columns'], t('Column widths must add up to @count.', array(
            '@count' => $values['percent_width'],
          )));
        }
      }
    }
  }
}