You are here

function panels_stylizer_edit_pane_style_form_validate in Panels 6.3

Same name and namespace in other branches
  1. 7.3 plugins/styles/stylizer.inc \panels_stylizer_edit_pane_style_form_validate()

Validate to see if we need to check the preconfigured values.

1 string reference to 'panels_stylizer_edit_pane_style_form_validate'
panels_stylizer_pane_add_style in plugins/styles/stylizer.inc
Allow on-the-fly creation of styles in panes.

File

plugins/styles/stylizer.inc, line 298
Definition of the 'stylizer' panel style.

Code

function panels_stylizer_edit_pane_style_form_validate(&$form, &$form_state) {
  if (!user_access('administer panels styles')) {
    return;
  }

  // Only validate if preconfigured is checked.
  if ($form_state['values']['preconfigured'] && !empty($form_state['clicked_button']['#wizard type'])) {
    if (empty($form_state['values']['admin_title'])) {
      form_error($form['panels']['admin_title'], t('You must choose an administrative title.'));
    }

    // If this is new, make sure the name is unique:
    if ($form_state['op'] == 'add') {
      if (empty($form_state['values']['name'])) {
        form_error($form['panels']['name'], t('You must choose a machine name.'));
      }
      ctools_include('export');
      $test = ctools_export_crud_load('stylizer', $form_state['values']['name']);
      if ($test) {
        form_error($form['panels']['name'], t('That name is used by another style: @page', array(
          '@page' => $test->admin_title,
        )));
      }

      // Ensure name fits the rules:
      if (preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['name'])) {
        form_error($form['panels']['name'], t('Name must be alphanumeric or underscores only.'));
      }
    }
  }
}