diff --git a/includes/phone.element.inc b/includes/phone.element.inc index 3cd0ef1..753c4e6 100644 --- a/includes/phone.element.inc +++ b/includes/phone.element.inc @@ -21,7 +21,7 @@ function _phone_element_info() { ), '#phone_settings' => array( 'use_tel_input' => TRUE, - 'number_size' => 15, + 'number_size' => 30, 'numbertype_allowed_values' => array( 'home' => t('Home'), 'work' => t('Work'), @@ -32,7 +32,7 @@ function _phone_element_info() { 'enable_numbertype' => TRUE, 'numbertype_allowed_values_position' => 'before', 'enable_extension' => FALSE, - 'extension_size' => 6, + 'extension_size' => 7, 'country_options' => array( 'enable_default_country' => TRUE, 'default_country' => NULL, diff --git a/phone.install b/phone.install index c2c8287..648de72 100644 --- a/phone.install +++ b/phone.install @@ -44,36 +44,38 @@ function phone_enable() { * Implements hook_field_schema(). */ function phone_field_schema($field) { - $settings = $field['settings']; - - $schema = array( - 'columns' => array( - 'numbertype' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'default' => NULL, - ), - 'number' => array( - 'type' => 'varchar', - 'length' => $settings['number_size'], - 'not null' => FALSE, - 'default' => NULL, - ), - 'countrycode' => array( - 'type' => 'varchar', - 'length' => 2, - 'not null' => FALSE, - 'default' => NULL, - ), - 'extension' => array( - 'type' => 'varchar', - 'length' => $settings['extension_size'], - 'not null' => FALSE, - 'default' => NULL, - ), + $columns = array( + 'numbertype' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + 'default' => NULL, + ), + 'number' => array( + 'type' => 'varchar', + 'length' => 30, + 'not null' => FALSE, + 'default' => NULL, + ), + 'countrycode' => array( + 'type' => 'varchar', + 'length' => 2, + 'not null' => FALSE, + 'default' => NULL, + ), + 'extension' => array( + 'type' => 'varchar', + 'length' => 7, + 'not null' => FALSE, + 'default' => NULL, ), ); - return $schema; + return array( + 'columns' => $columns, + 'indexes' => array( + 'countrycode' => array('countrycode'), + 'numbertype' => array('numbertype'), + ), + ); } diff --git a/phone.module b/phone.module index d28439c..86cc1f7 100644 --- a/phone.module +++ b/phone.module @@ -170,8 +170,6 @@ function phone_field_info() { 'label' => t('Phone'), 'description' => t('Store a number, country code, and optional extension and number type on an entity.'), 'settings' => array( - 'number_size' => 15, - 'extension_size' => 6, 'numbertype_allowed_values_type' => 'custom', 'numbertype_allowed_values' => array( 'home' => t('Home'), @@ -323,31 +321,6 @@ function phone_field_settings_form($field, $instance, $has_data) { $form = array(); - $form['number_size'] = array( - '#type' => 'textfield', - '#title' => t('Maximum size of a phone field'), - '#default_value' => $settings['number_size'], - '#element_validate' => array('_element_validate_integer_positive'), - '#required' => TRUE, - '#description' => t('International numbers are a maximum of 15 digits with additional country code. Default is %length.', array('%length' => $defaults['number_size'])), - ); - - $form['extension_size'] = array( - '#type' => 'textfield', - '#title' => t('Maxium size of extension field'), - '#default_value' => $settings['extension_size'], - '#element_validate' => array('_element_validate_integer_positive'), - '#description' => t('This controls the maximum amount of data that can be stored in an extension field.'), - '#states' => array( - 'visible' => array( - ':input[name="instance[widget][settings][enable_extension]"]' => array('checked' => TRUE), - ), - 'required' => array( - ':input[name="instance[widget][settings][enable_extension]"]' => array('checked' => TRUE), - ), - ), - ); - $form['numbertype_allowed_values_type'] = array( '#type' => 'radios', '#title' => t('Number type allowed values'), @@ -359,6 +332,14 @@ function phone_field_settings_form($field, $instance, $has_data) { ), '#required' => TRUE, '#description' => t('Determines which options list will be used for number type allowed valus.'), + '#states' => array( + 'visible' => array( + ':input[name="field[settings][numbertype_allowed_values_type]"]' => array('value' => 'custom'), + ), + 'invisible' => array( + ':input[name="instance[widget][settings][enable_numbertype]"]' => array('checked' => FALSE), + ), + ), ); $form['numbertype_allowed_values'] = array( @@ -714,6 +695,8 @@ function phone_field_widget_info() { 'enable_numbertype' => TRUE, 'numbertype_allowed_values_position' => 'before', 'enable_extension' => FALSE, + 'number_size' => 30, + 'extension_size' => 7, 'use_tel_input' => TRUE, ), ), @@ -739,7 +722,7 @@ function phone_field_widget_settings_form($field, $instance) { '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => FALSE, - '#weight' => -4, + '#weight' => -3, '#attached' => array( 'css' => array( $module_path . '/theme/phone-settings.css', @@ -819,12 +802,39 @@ function phone_field_widget_settings_form($field, $instance) { '#description' => t('Select the position of the country code selection field relative to the phone number text field.'), ); + $form['number_size'] = array( + '#type' => 'textfield', + '#title' => t('Maximum size of a phone field'), + '#default_value' => $settings['number_size'], + '#element_validate' => array('_element_validate_integer_positive'), + '#required' => TRUE, + '#description' => t('International numbers are a maximum of 15 digits with additional country code. Default is %length.', array('%length' => $defaults['number_size'])), + '#weight' => -2.8, + ); + $form['enable_extension'] = array( '#type' => 'checkbox', '#title' => t('Enable phone extension support'), '#default_value' => $settings['enable_extension'], '#description' => t('Check this to enable the phone number extension field.'), - '#weight' => -3, + '#weight' => -2.6, + ); + + $form['extension_size'] = array( + '#type' => 'textfield', + '#title' => t('Maxium size of extension field'), + '#default_value' => $settings['extension_size'], + '#element_validate' => array('_element_validate_integer_positive'), + '#description' => t('This controls the maximum amount of data that can be stored in an extension field.'), + '#states' => array( + 'visible' => array( + ':input[name="instance[widget][settings][enable_extension]"]' => array('checked' => TRUE), + ), + 'required' => array( + ':input[name="instance[widget][settings][enable_extension]"]' => array('checked' => TRUE), + ), + ), + '#weight' => -2.4, ); $form['enable_numbertype'] = array( @@ -832,7 +842,7 @@ function phone_field_widget_settings_form($field, $instance) { '#title' => t('Enable phone number type support'), '#default_value' => $settings['enable_numbertype'], '#description' => t('Check this to enable the phone number type field.'), - '#weight' => -2, + '#weight' => -2.2, ); $form['numbertype_allowed_values_position'] = array( @@ -849,14 +859,14 @@ function phone_field_widget_settings_form($field, $instance) { ':input[name="instance[widget][settings][enable_numbertype]"]' => array('checked' => TRUE), ), ), - '#weight' => -1, + '#weight' => -2, ); $form['use_tel_input'] = array( '#type' => 'checkbox', '#title' => t('Use input type=tel for editing'), '#default_value' => $settings['use_tel_input'], - '#weight' => 0, + '#weight' => -1, ); return $form;