Commit b89c34a9 authored by Jelle Sebreghts's avatar Jelle Sebreghts
Browse files

start for refactoring settings

parent 2abc479a
This diff is collapsed.
......@@ -5,7 +5,7 @@
*/
/**
* Implements hook_install().
* Implements hook_enable().
*/
function clientside_validation_enable() {
//support for module like e.g. select_or_other
......@@ -18,6 +18,61 @@ function clientside_validation_enable() {
->execute();
}
/**
* Implements hook_schema()
*/
function clientside_validation_schema() {
$schema = array();
$schema['clientside_validation_settings'] = array(
'description' => 'Table for storing Clientside Validation Settings',
'fields' => array(
'cvsid' => array(
'description' => 'The primary identifier for the clientside validation settings',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'The type of setting: content_type, webform or custom',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'description' => 'The status for this form. 1 for enabled (validate), 0 for disabled (don\'t validate)',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
'form_id' => array(
'description' => 'The form id these settings apply to',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'settings' => array(
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
'translatable' => TRUE,
),
),
'indexes' => array(
'clientside_validation_settings_form_id' => array('form_id'),
'clientside_validation_settings_type' => array('type'),
'clientside_validation_settings_form_id_type' => array('form_id', 'type'),
),
'unique keys' => array(
'cvs_form_id' => array('form_id'),
),
'primary key' => array('cvsid'),
);
return $schema;
}
/**
* Clientside validation was split up into form validation, webform validation and fapi validation.
* This update enables the form and webform clientside validation module. It does not enable the
......@@ -26,3 +81,13 @@ function clientside_validation_enable() {
function clientside_validation_update_7100() {
module_enable(array('clientside_validation_form', 'clientside_validation_webform'));
}
/**
* The settings for Clientside Validation were restructured and put into a separate table,
* This update will create this table.
*/
function clientside_validation_update_7101() {
if(!db_table_exists('clientside_validation_settings')) {
db_create_table('clientside_validation_settings', drupal_get_schema('clientside_validation_settings', TRUE));
}
}
......@@ -29,7 +29,7 @@ function clientside_validation_menu() {
'position' => 'right',
'weight' => -10,
'page callback' => 'drupal_get_form',
'page arguments' => array('clientside_validation_admin_settings'),
'page arguments' => array('clientside_validation_general_settings_form'),
'access arguments' => array('access administration pages'),
'file' => 'clientside_validation.admin.inc',
);
......@@ -37,7 +37,20 @@ function clientside_validation_menu() {
'title' => 'Clientside Validation',
'description' => 'Administer clientside validation.',
'page callback' => 'drupal_get_form',
'page arguments' => array('clientside_validation_admin_settings'),
'page arguments' => array('clientside_validation_general_settings_form'),
'access arguments' => array('administer site configuration'),
'file' => 'clientside_validation.admin.inc',
);
$items['admin/config/validation/clientside_validation/general'] = array(
'title' => 'General',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
$items['admin/config/validation/clientside_validation/default'] = array(
'title' => 'Default',
'type' => MENU_LOCAL_TASK,
'page callback' => 'drupal_get_form',
'page arguments' => array('clientside_validation_settings_form'),
'access arguments' => array('administer site configuration'),
'file' => 'clientside_validation.admin.inc',
);
......@@ -1021,3 +1034,57 @@ function clientside_validation_theme($existing, $type, $theme, $path) {
function theme_clientside_error($variables) {
return t($variables['message'], $variables['placeholders']);
}
function clientside_validation_settings_load($cvsid = NULL, $type = NULL, $form_id = NULL) {
if ($type == 'default') {
$default_settings = array(
'type' => 'default',
'validate_options' => array(
'disable_html5' => 1,
'validate_onsubmit' => 1,
'validate_onblur' => 1,
'validate_onblur_always' => 0,
'validate_onkeyup' => 1,
'show_messages' => 0,
),
'error' => array(
'prefix' => '',
'suffix' => '',
'scrollto_errormessage' => 1,
'scroll_speed' => 1000,
'error_element' => 'label',
),
'error_placement' => array(
'error_placement_default' => CLIENTSIDE_VALIDATION_TOP_OF_FORM,
'jquery_selector' => '',
'custom_error_function' => '',
),
'include_hidden' => array(
'include_hidden' => '',
'validate_tabs' => '',
),
);
return variable_get('clientside_validation_default_settings', $default_settings);
}
$query = db_select('clientside_validation_settings');
if (!empty($cvsid)) {
$query->condition('cvsid', $cvsid);
}
if (!empty($type)){
$query->condition('type', $type);
}
if (!empty($form_id)) {
$query->condition('form_id', $form_id);
}
$result = $query->execute();
// a single id was given -> one result, so only return one row
if (is_numeric($cvsid)) {
return $result->fetchAssoc();
}
// a single form_id was given -> one result, so only return one row
if (is_string($form_id)) {
return $result->fetchAssoc();
}
return $result->fetchAllAssoc('cvsid');
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment