function biblio_admin_keyword_edit_form in Bibliography Module 7
Same name and namespace in other branches
- 6.2 includes/biblio.admin.inc \biblio_admin_keyword_edit_form()
- 6 biblio.admin.inc \biblio_admin_keyword_edit_form()
- 7.2 includes/biblio.admin.inc \biblio_admin_keyword_edit_form()
_state
Parameters
$form:
$keyword_id:
Return value
multitype:string number NULL
1 string reference to 'biblio_admin_keyword_edit_form'
- biblio_menu in ./
biblio.module - Implements hook_menu().
File
- includes/
biblio.admin.inc, line 2810 - biblio.admin.inc
Code
function biblio_admin_keyword_edit_form($form, &$form_state, $keyword_id) {
$options = array();
$keywords = array();
$destination = NULL;
$keyword = db_query('SELECT * FROM {biblio_keyword_data} bkd WHERE bkd.kid = :kid ', array(
':kid' => $keyword_id,
))
->fetchObject();
$base = variable_get('biblio_base', 'biblio');
// $path = (strpos($_GET['q'], 'config')) ? 'admin/config/content/biblio/keywords' : $base . '/keywords';.
if (isset($_GET['destination'])) {
$destination = $_GET['destination'];
}
if (!$destination && isset($form_state['complete form']['#action'])) {
$action = drupal_parse_url($form_state['complete form']['#action']);
$destination = isset($action['query']['destination']) ? $action['query']['destination'] : NULL;
}
if (!$destination) {
$destination = $base . '/keywords';
}
$form_state['redirect'] = $destination;
$form['kid'] = array(
'#type' => 'value',
'#value' => $keyword_id,
);
$form['word'] = array(
'#type' => 'textfield',
'#title' => t('Keyword'),
'#default_value' => $keyword->word,
'#size' => 100,
'#weight' => -10,
'#required' => TRUE,
'#maxlength' => 255,
);
$result = db_query("SELECT kd.word, kd.kid, count(*) as use_count FROM {biblio_keyword_data} kd\n LEFT JOIN {biblio_keyword} bk on bk.kid = kd.kid\n WHERE LOWER(word) LIKE LOWER(:word)\n AND kd.kid <> :kid\n GROUP BY kd.kid, kd.word", array(
':word' => '%%' . drupal_substr($keyword->word, 0, 5) . '%%',
':kid' => $keyword_id,
));
foreach ($result as $keyword) {
$keywords[] = $keyword;
}
if (isset($form_state['biblio_add_merge_keywords'])) {
$keywords = array_merge($keywords, $form_state['biblio_add_merge_keywords']);
}
foreach ($keywords as $keyword) {
$options[$keyword->kid] = array(
'keyword' => array(
'data' => array(
'#type' => 'link',
'#title' => $keyword->word . ' (' . $keyword->use_count . ')',
'#href' => $destination . '/' . $keyword->kid . '/edit',
'#options' => array(
'query' => array(
'destination' => $destination,
),
),
),
),
);
}
$form['merge'] = array(
'#type' => 'fieldset',
'#title' => t('Keyword Merge'),
'#description' => t('If you wish to consolodate references to multiple keywords into single reference to: <b><u>!kw</u></b>, select the others from the list below. This will remove the selected keywords from the database and replace references to them with a reference to: <b><u>!kw</u></b>. You should only do this if you are sure the other keywords represent the same keyword as the one being edited.', array(
'!kw' => $keyword->word,
)),
'#weight' => 5,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$header = array(
'keyword' => t('Similar keywords '),
);
$form['merge']['merge_words'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No similar keywords automatically detected, use the search box below to manually add others.'),
'#prefix' => '<div id="biblio-keyword-merge-table">',
'#suffix' => '</div>',
);
$form['merge']['search'] = array(
'#type' => 'textfield',
'#title' => t('Keyword search'),
'#autocomplete_path' => 'biblio/autocomplete/biblio_keywords',
'#description' => t('Use this field to find other keywords you would like to merge with: <b><u>!kw</u></b>, then click the "Add to merge list" button. (The merge will not happen until the "Save" button is clicked)', array(
'!kw' => $keyword->word,
)),
);
$form['merge']['add'] = array(
'#type' => 'submit',
'#value' => t('Add to merge list'),
'#submit' => array(
'biblio_add_merge_keyword',
),
'#ajax' => array(
'callback' => 'biblio_add_merge_keyword_callback',
'wrapper' => 'biblio-keyword-merge-table',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 6,
);
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#weight' => 7,
);
$form['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#weight' => 8,
);
return $form;
}