diff --git a/usasearch.admin.inc b/usasearch.admin.inc index bdc04a0..11c89ed 100644 --- a/usasearch.admin.inc +++ b/usasearch.admin.inc @@ -20,6 +20,19 @@ function usasearch_admin() { '#description' => t('Please enter the handle for the DigitalGov Search site you want to send your content to, e.g., "dept-agency.gov"', array('@usasearch_affiliates_url' => url('https://search.usa.gov/affiliates'))), '#required' => TRUE, ); + $form['usasearch_i14y_enabled'] = array( + '#type' => 'checkbox', + '#title' => t('Enable i14y API'), + '#default_value' => variable_get('usasearch_i14y_enabled', TRUE), + '#description' => t('Check this box to use the i14y API. More information about i14y API usage and setup.'), + ); + $depends_on_i14y = array( + '#states' => array( + 'invisible' => array( + ':input[name="usasearch_i14y_enabled"]' => array('checked' => FALSE), + ), + ), + ); $form['usasearch_drawer_handle'] = array( '#type' => 'textfield', '#title' => t('Drawer handle'), @@ -27,15 +40,13 @@ function usasearch_admin() { '#size' => 30, '#maxlength' => 30, '#description' => t('Please enter the handle for the i14y Drawer you created in the above site, where your content will be indexed, e.g. "agency" (See https://search.usa.gov/sites/YOURSITEID/i14y_drawers)'), - '#required' => TRUE, - ); + ) + $depends_on_i14y; $form['usasearch_api_password'] = array( '#type' => 'textfield', '#title' => t('i14y API Secret Token'), '#default_value' => variable_get('usasearch_api_password', ''), - '#required' => TRUE, '#description' => t('Enter the Secret Token provided in your search site: go to https://search.usa.gov/sites/YOURSITEID/i14y_drawers and click Show next to the drawer.'), - ); + ) + $depends_on_i14y; $form['usasearch_autocomplete'] = array( '#type' => 'checkbox', '#title' => t('Enable autocomplete'), @@ -59,33 +70,33 @@ function usasearch_admin() { '#maxlength' => 50, '#description' => t('If set, the value of this field will be used when assembling the path to which indexed records should refer. This is useful in cases when you use a non-public edit domain and want to ensure that search records reference the public domain rather than the edit domain.'), '#required' => FALSE, - ); + ) + $depends_on_i14y; $form['usasearch_use_rules'] = array( '#type' => 'checkbox', '#title' => t('Use rules to index content'), '#default_value' => variable_get('usasearch_use_rules', FALSE), '#description' => t('Check this box to index content manually with rules. The DigitalGov Search index will not be updated unless specified in a rule action'), - ); + ) + $depends_on_i14y; $form['usasearch_view_modes'] = array( '#type' => 'select', '#title' => t('Results description view mode'), '#options' => usasearch_entity_view_modes('node'), '#default_value' => variable_get('usasearch_view_modes', 'teaser'), '#description' => t('Select a preferred view mode to define description shown in search results. The view mode will need to be enabled and configured for each content type. If the view mode is not available for a content type "Teaser" will be used.'), - ); + ) + $depends_on_i14y; $form['usasearch_content_view_modes'] = array( '#type' => 'select', '#title' => t('Indexed content view mode'), '#options' => usasearch_entity_view_modes('node'), '#default_value' => variable_get('usasearch_content_view_modes', 'full'), '#description' => t('Select a preferred view mode to define the content that gets indexed. The view mode will need to be enabled and configured for each content type. If the view mode is not available for a content type "Default" will be used.'), - ); + ) + $depends_on_i14y; $form['usasearch_include_if_not_excluded'] = array( '#type' => 'checkbox', '#title' => t('Include by content type unless explicitly excluded.'), '#description' => t('If a content type is enabled for indexing and there is no record of the node in the database as being excluded for indexing then index it.'), '#default_value' => variable_get('usasearch_include_if_not_excluded', TRUE), - ); + ) + $depends_on_i14y; return system_settings_form($form); } @@ -93,9 +104,18 @@ function usasearch_admin() { * Validate settings form. */ function usasearch_admin_validate($form, &$form_state){ + // Require some inputs if i14y is enabled. + if ($form_state['input']['usasearch_i14y_enabled']) { if ($form_state['values']['usasearch_alternate_baseurl'] && !valid_url($form_state['values']['usasearch_alternate_baseurl'], TRUE)) { - form_set_error('usasearch_alternate_base_url', 'If set, the value of Alternate Indexing Domain must be a valid domain.'); + form_set_error('usasearch_alternate_baseurl', t('If set, the value of Alternate Indexing Domain must be a valid domain.')); } + if (empty($form_state['input']['usasearch_drawer_handle'])) { + form_set_error('usasearch_drawer_handle', t('If i14y is enabled, the Drawer Handle is required.')); + } + if (empty($form_state['input']['usasearch_api_password'])) { + form_set_error('usasearch_api_password', t('If i14y is enabled, the API Password is required.')); + } + } } /** diff --git a/usasearch.install b/usasearch.install index 20c02e8..99309ba 100644 --- a/usasearch.install +++ b/usasearch.install @@ -22,6 +22,7 @@ function usasearch_uninstall() { variable_del('usasearch_alternate_baseurl'); variable_del('usasearch_search_page'); variable_del('usasearch_use_rules'); + variable_del('usasearch_i14y_enabled'); } /** diff --git a/usasearch.module b/usasearch.module index c94bfa0..c0a2ad5 100644 --- a/usasearch.module +++ b/usasearch.module @@ -28,6 +28,9 @@ function usasearch_menu() * Implements hook_form_BASE_FORM_ID_alter(). */ function usasearch_form_node_form_alter(&$form, &$form_state, $form_id) { + if (!variable_get('usasearch_i14y_enabled', TRUE)) { + return; + } // Include/exclude node from usasearch index $node = $form['#node']; $usasearch_content_type_settings = variable_get("usasearch_node_include_{$node->type}", TRUE); @@ -94,6 +97,9 @@ function usasearch_save_per_node_settings($node, $setting){ * Implements hook_form_FORM_ID_alter(). */ function usasearch_form_node_type_form_alter(&$form, &$form_state, $form_id) { + if (!variable_get('usasearch_i14y_enabled', TRUE)) { + return; + } $node_type = $form['#node_type']->type; $variable_name = "usasearch_node_include_{$node_type}"; $form['usasearch_settings'] = array( diff --git a/usasearch_api/usasearch_api.module b/usasearch_api/usasearch_api.module index a6f5770..fa068f6 100644 --- a/usasearch_api/usasearch_api.module +++ b/usasearch_api/usasearch_api.module @@ -38,8 +38,10 @@ function usasearch_api_node_delete($node) { } } -function usasearch_api_index_document($node, $action) -{ +function usasearch_api_index_document($node, $action) { + if (!variable_get('usasearch_i14y_enabled', TRUE)) { + return; + } $force = $action == 'delete'; $document = usasearch_api_convert_node_to_document($node, $force); if ($document) {