#471018 follow-up by sun: Apply generic pattern/js for hiding machine readable names to taxonomy vocabularies.
parent
12df73d2cf
commit
fbe690c624
|
@ -103,7 +103,6 @@ function theme_taxonomy_overview_vocabularies($form) {
|
|||
* @see taxonomy_form_vocabulary_submit()
|
||||
*/
|
||||
function taxonomy_form_vocabulary(&$form_state, $edit = array()) {
|
||||
drupal_add_js(drupal_get_path('module', 'taxonomy') . '/vocabulary.js');
|
||||
if (!is_array($edit)) {
|
||||
$edit = (array)$edit;
|
||||
}
|
||||
|
@ -130,7 +129,20 @@ function taxonomy_form_vocabulary(&$form_state, $edit = array()) {
|
|||
'#default_value' => $edit['name'],
|
||||
'#maxlength' => 255,
|
||||
'#required' => TRUE,
|
||||
'#field_suffix' => ' <small id="vocabulary-name-suffix"> </small>',
|
||||
'#field_suffix' => ' <small id="edit-name-suffix"> </small>',
|
||||
);
|
||||
$js_settings = array(
|
||||
'type' => 'setting',
|
||||
'data' => array(
|
||||
'machineReadableValue' => array(
|
||||
'name' => array(
|
||||
'text' => t('Machine name'),
|
||||
'target' => 'machine-name',
|
||||
'searchPattern' => '[^a-z0-9]+',
|
||||
'replaceToken' => '_',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['machine_name'] = array(
|
||||
'#type' => 'textfield',
|
||||
|
@ -139,6 +151,7 @@ function taxonomy_form_vocabulary(&$form_state, $edit = array()) {
|
|||
'#maxlength' => 255,
|
||||
'#description' => t('The unique machine readable name for this vocabulary, used for theme templates, can only contain lowercase letters, numbers and underscores.'),
|
||||
'#required' => TRUE,
|
||||
'#attached_js' => array(drupal_get_path('module', 'system') . '/system.js', $js_settings),
|
||||
);
|
||||
$form['help'] = array(
|
||||
'#type' => 'textfield',
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
// $Id$
|
||||
(function ($) {
|
||||
|
||||
Drupal.behaviors.contentTypes = {
|
||||
attach: function () {
|
||||
if ($('#edit-machine-name').val() == $('#edit-name').val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_') || $('#edit-machine-name').val() == '') {
|
||||
$('.form-item-machine-name').hide();
|
||||
$('#edit-name').keyup(function () {
|
||||
var machine = $(this).val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_');
|
||||
if (machine != '_' && machine != '') {
|
||||
$('#edit-machine-name').val(machine);
|
||||
$('#vocabulary-name-suffix').empty().append(' Machine name: ' + machine + ' [').append($('<a href="#">' + Drupal.t('Edit') + '</a>').click(function () {
|
||||
$('.form-item-machine-name').show();
|
||||
$('#vocabulary-name-suffix').hide();
|
||||
$('#edit-name').unbind('keyup');
|
||||
return false;
|
||||
})).append(']');
|
||||
}
|
||||
else {
|
||||
$('#edit-machine-name').val(machine);
|
||||
$('#vocabulary-name-suffix').text('');
|
||||
}
|
||||
});
|
||||
$('#edit-name').keyup();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery);
|
Loading…
Reference in New Issue