Commit 6ec04dbc authored by Alan Davison's avatar Alan Davison
Browse files

Issues 1411964, 399822 by Alan D.: String overrides for all forms; merge in Restricted Search

parent 4fab0afa
......@@ -119,7 +119,7 @@ CONFIGURATION
Since Keywords and Containing any fields are a bit confusing, even though
these are different: the basic forms "Keywords" is AND field and the
"Containing any ..." ia an OR field.
"Containing any ..." is an OR field.
So I disable the "Containing any ..." field:
- under "Containing any of the words settings"
......@@ -175,12 +175,10 @@ TODO
Local menu tab label overrides OR find the native method of doing this
Categories field
Languages field
Search result limits
Write tests
-- Maybes, depends on scale --
Add node level exclude from search options
Add new fields to the search form
MAINTAINERS
......
......@@ -9,10 +9,64 @@
* Called from search_config_form_search_admin_settings_alter().
*/
function _search_config_form_search_admin_settings_alter(&$form, $form_state) {
$settings = search_config_node_settings();
// String override options.
$string_overrides = search_config_string_overrides();
$form['search_config_string_overrides'] = array(
'#type' => 'fieldset',
'#theme' => 'search_config_admin_label_form',
'#title' => t('Labels and string overrides'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'labels' => array(),
'title_display' => array(),
'#tree' => TRUE,
);
$title_display_options = array(
'default' => t('Default'),
'invisible' => t('Hidden'),
'description' => t('Below'),
);
$slabels = array(
'basic' => array(t('Keywords'), t('Enter your keywords')),
'basic_with_keys' => array(t('Keywords (with search keys)'), t('Enter your keywords')),
'basic_submit' => array(t('Submit button'), t('Search')),
'advanced_fieldset' => array(t('Wrapping fieldset'), t('Advanced search')),
'advanced_fieldset_with_keys' => array(t('Wrapping fieldset (with search keys)'), t('Advanced search')),
'advanced_any' => array(t('Containing any ...'), t('Containing any of the words')),
'advanced_phrase' => array(t('Containing the phrase'), t('Containing the phrase')),
'advanced_none' => array(t('Containing none ...'), t('Containing none of the words')),
'advanced_type' => array(t('Types'), t('Only of the type(s)')),
'advanced_language' => array(t('Language selector'), t('Languages')),
'advanced_submit' => array(t('Submit button'), t('Advanced search')),
);
$form['search_config_string_overrides']['#field-labels'] = $slabels;
foreach ($slabels as $skey => $slabel) {
$form['search_config_string_overrides']['labels'] += array(
$skey => array(
'#type' => 'textfield',
'#title' => $slabel[0],
'#title_display' => 'invisible',
'#default_value' => $string_overrides['labels'][$skey],
'#description' => t('t() string: !translation' ,
array('%label' => $slabel[1], '!translation' => '!search_config:' . $skey)),
'#size' => 40,
),
);
if (isset($string_overrides['title_display'][$skey])) {
$form['search_config_string_overrides']['title_display'] += array(
$skey => array(
'#type' => 'radios',
'#title' => $slabel[0],
'#title_display' => 'invisible',
'#default_value' => $string_overrides['title_display'][$skey],
'#options' => $title_display_options,
),
);
}
}
// Form configuration options.
$settings = search_config_node_settings();
$role_options = array_map('check_plain', user_roles());
$form['content_node_search_config'] = array(
'#type' => 'fieldset',
......@@ -68,64 +122,11 @@ function _search_config_form_search_admin_settings_alter(&$form, $form_state) {
)
),
),
'string_overrides' => array(
'#type' => 'fieldset',
'#theme' => 'search_config_admin_label_form',
'#title' => t('Labels and string overrides'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'labels' => array(),
'title_display' => array(),
),
'fields' => array(
'#type' => 'item',
),
);
$title_display_options = array(
'default' => t('Default'),
'invisible' => t('Hidden'),
'description' => t('Below'),
);
$slabels = array(
'basic' => array(t('Keywords'), t('Enter your keywords')),
'basic_with_keys' => array(t('Keywords (with search keys)'), t('Enter your keywords')),
'basic_submit' => array(t('Submit button'), t('Search')),
'advanced_fieldset' => array(t('Wrapping fieldset'), t('Advanced search')),
'advanced_fieldset_with_keys' => array(t('Wrapping fieldset (with search keys)'), t('Advanced search')),
'advanced_any' => array(t('Containing any ...'), t('Containing any of the words')),
'advanced_phrase' => array(t('Containing the phrase'), t('Containing the phrase')),
'advanced_none' => array(t('Containing none ...'), t('Containing none of the words')),
'advanced_type' => array(t('Types'), t('Only of the type(s)')),
'advanced_language' => array(t('Language selector'), t('Languages')),
'advanced_submit' => array(t('Submit button'), t('Advanced search')),
);
$form['content_node_search_config']['string_overrides']['#field-labels'] = $slabels;
foreach ($slabels as $skey => $slabel) {
$form['content_node_search_config']['string_overrides']['labels'] += array(
$skey => array(
'#type' => 'textfield',
'#title' => $slabel[0],
'#title_display' => 'invisible',
'#default_value' => $string_overrides['labels'][$skey],
'#description' => t('t() string: !translation' ,
array('%label' => $slabel[1], '!translation' => '!search_config:' . $skey)),
'#size' => 40,
),
);
if (isset($string_overrides['title_display'][$skey])) {
$form['content_node_search_config']['string_overrides']['title_display'] += array(
$skey => array(
'#type' => 'radios',
'#title' => $slabel[0],
'#title_display' => 'invisible',
'#default_value' => $string_overrides['title_display'][$skey],
'#options' => $title_display_options,
),
);
}
}
$fields = array(
'containing_any' => t('Containing any of the words'),
'containing_phrase' => t('Containing the phrase'),
......
......@@ -218,11 +218,13 @@ function search_config_node_search_result($node) {
* Implements of hook_form_FORM_alter().
*/
function search_config_form_search_form_alter(&$form, $form_state) {
// See if this is the node search form with the advanced fieldset present.
if (isset($form['advanced']) && isset($form['module']['#value'])
&& $form['module']['#value'] == 'node') {
// Update the node search form.
if (isset($form['module']['#value']) && $form['module']['#value'] == 'node') {
module_load_include('inc', 'search_config', 'search_config.node');
_search_config_advanced_form($form, $form_state);
_search_config_set_string_overrides($form, $form_state);
if (isset($form['advanced'])) {
_search_config_advanced_form($form, $form_state);
}
}
}
......@@ -242,8 +244,7 @@ function search_config_form_search_admin_settings_alter(&$form, $form_state) {
* Additional submit handler to save the additional fields added by the form alter.
*/
function search_config_search_admin_settings_alter(&$form, $form_state) {
variable_set('search_config_string_overrides', $form_state['values']['content_node_search_config']['string_overrides']);
unset($form_state['values']['content_node_search_config']['string_overrides']);
variable_set('search_config_string_overrides', $form_state['values']['search_config_string_overrides']);
variable_set('search_config', $form_state['values']['content_node_search_config']);
}
......@@ -312,20 +313,30 @@ function search_config_form_node_form_alter(&$form, $form_state) {
}
/**
* Implements hook_node_submit().
* Implements hook_node_insert().
*
* Inserts the excluded flag for both node insert and update hooks.
*/
function search_config_node_insert($node) {
if (!empty($node->search_config_exclude)) {
$record = array(
'entity_type' => 'node',
'entity_id' => $node->nid,
'exclude' => 1,
);
drupal_write_record('search_config_exclude', $record);
}
}
/**
* Implements hook_node_update().
*
* @see menu_form_node_form_alter()
* Deletes any existing records and calls search_config_node_insert() to insert
* any required rows.
*/
function search_config_node_submit($node, $form, $form_state) {
function search_config_node_update($node) {
if (isset($node->search_config_exclude)) {
db_delete('search_config_exclude')->condition('entity_id', $node->nid)->condition('entity_type', 'node')->execute();
if ($node->search_config_exclude) {
$record = array(
'entity_type' => 'node',
'entity_id' => $node->nid,
'exclude' => 1,
);
drupal_write_record('search_config_exclude', $record);
}
search_config_node_insert($node);
}
}
......@@ -6,53 +6,40 @@
*/
/**
* This function implements the options to configure the default Drupal search
* form, including type filter, field visibility, form visibility, etc.
* Does the string overrides unconditional on what other changes are pending for
* the form.
*/
function _search_config_advanced_form(&$form, $form_state) {
global $user, $search_config_node_results;
// Settings
$settings = search_config_node_settings();
$fs_phrase = $settings['fields']['containing_phrase'];
$fs_any = $settings['fields']['containing_any'];
$fs_none = $settings['fields']['containing_none'];
$fs_types = $settings['fields']['types'];
function _search_config_set_string_overrides(&$form, $form_state) {
$labels = search_config_string_overrides('labels');
// Return the form for super admin unchanged
if ($user->uid == 1 && !empty($settings['restrictions']['admin_bypass'])) {
return $form;
// The two submit buttons.
if (isset($form['basic']['submit']) && !empty($labels['basic_submit'])) {
$form['basic']['submit']['#value'] = t('!search_config:basic_submit', array('!search_config:basic_submit' => $labels['basic_submit']));
}
// Form elements
$fkeys = &$form['basic']['keys'];
$fkeywords = &$form['advanced']['keywords'];
$ftype = &$form['advanced']['type'];
$flang = NULL;
if (isset($form['advanced']['language'])) {
$flang = &$form['advanced']['language'];
if (isset($form['advanced']['submit']) && !empty($labels['advanced_submit'])) {
$form['advanced']['submit']['#value'] = t('!search_config:advanced_submit', array('!search_config:advanced_submit' => $labels['advanced_submit']));
}
// Do the labels first.
$labels = search_config_string_overrides('labels');
// Other form elements. Map into an array to iterate over each element.
$title_display = search_config_string_overrides('title_display');
// The two submit buttons.
if (!empty($labels['basic_submit'])) {
$form['basic']['submit']['#value'] = t('!search_config:basic_submit', array('!search_config:basic_submit' => $labels['basic_submit']));
$label_elements = array();
if (isset($form['basic'])) {
$label_elements['basic'] = &$form['basic']['keys'];
}
if (!empty($labels['advanced_submit'])) {
$form['advanced']['submit']['#value'] = t('!search_config:advanced_submit', array('!search_config:advanced_submit' => $labels['advanced_submit']));
if (isset($form['advanced'])) {
$label_elements['advanced_fieldset'] = &$form['advanced'];
$label_elements['advanced_type'] = &$form['advanced']['type'];
$fkeywords = &$form['advanced']['keywords'];
$label_elements['advanced_any'] = &$fkeywords['or'];
$label_elements['advanced_phrase'] = &$fkeywords['phrase'];
$label_elements['advanced_none'] = &$fkeywords['negative'];
if (isset($form['advanced']['language'])) {
$label_elements['advanced_language'] = &$form['advanced']['language'];
}
}
$label_elements = array(
'basic' => &$fkeys,
'advanced_fieldset' => &$form['advanced'],
'advanced_any' => &$fkeywords['or'],
'advanced_phrase' => &$fkeywords['phrase'],
'advanced_none' => &$fkeywords['negative'],
'advanced_type' => &$ftype,
'advanced_language' => &$flang,
);
foreach ($label_elements as $key => $element) {
if (empty($element)) {
continue;
......@@ -80,6 +67,35 @@ function _search_config_advanced_form(&$form, $form_state) {
}
}
}
}
/**
* This function implements the options to configure the default Drupal search
* form, including type filter, field visibility, form visibility, etc.
*/
function _search_config_advanced_form(&$form, $form_state) {
global $user, $search_config_node_results;
// Settings
$settings = search_config_node_settings();
$fs_phrase = $settings['fields']['containing_phrase'];
$fs_any = $settings['fields']['containing_any'];
$fs_none = $settings['fields']['containing_none'];
$fs_types = $settings['fields']['types'];
// Return the form for super admin unchanged
if ($user->uid == 1 && !empty($settings['restrictions']['admin_bypass'])) {
return $form;
}
// Form elements
$fkeys = &$form['basic']['keys'];
$fkeywords = &$form['advanced']['keywords'];
$ftype = &$form['advanced']['type'];
$flang = NULL;
if (isset($form['advanced']['language'])) {
$flang = &$form['advanced']['language'];
}
// Change the form fieldset.
switch ($settings['forms']['advanced_expand']) {
......
Markdown is supported
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