Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
e45e8b2a
Commit
e45e8b2a
authored
14 years ago
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
#902644
follow-up: Committing missing JS file.
parent
cf11af68
No related branches found
Branches containing commit
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
misc/machine-name.js
+110
-0
110 additions, 0 deletions
misc/machine-name.js
modules/system/system.admin.css
+10
-0
10 additions, 0 deletions
modules/system/system.admin.css
modules/system/system.module
+12
-0
12 additions, 0 deletions
modules/system/system.module
with
132 additions
and
0 deletions
misc/machine-name.js
0 → 100644
+
110
−
0
View file @
e45e8b2a
// $Id$
(
function
(
$
)
{
/**
* Attach the machine-readable name form element behavior.
*/
Drupal
.
behaviors
.
machineName
=
{
/**
* Attaches the behavior.
*
* @param settings.machineName
* A list of elements to process, keyed by the HTML ID of the form element
* containing the human-readable value. Each element is an object defining
* the following properties:
* - target: The HTML ID of the machine name form element.
* - suffix: The HTML ID of a container to show the machine name preview in
* (usually a field suffix after the human-readable name form element).
* - label: The label to show for the machine name preview.
* - replace_pattern: A regular expression (without modifiers) matching
* disallowed characters in the machine name; e.g., '[^a-z0-9]+'.
* - replace: A character to replace disallowed characters with; e.g., '_'
* or '-'.
*/
attach
:
function
(
context
,
settings
)
{
var
self
=
this
;
$
.
each
(
settings
.
machineName
,
function
(
source_id
,
options
)
{
var
$source
=
$
(
source_id
,
context
).
addClass
(
'
machine-name-source
'
);
var
$target
=
$
(
options
.
target
,
context
).
addClass
(
'
machine-name-target
'
);
var
$suffix
=
$
(
options
.
suffix
,
context
);
var
$wrapper
=
$target
.
parents
(
'
.form-item:first
'
);
// All elements have to exist.
if
(
!
$source
.
length
||
!
$target
.
length
||
!
$suffix
.
length
||
!
$wrapper
.
length
)
{
return
;
}
// Skip processing upon a form validation error on the machine name.
if
(
$target
.
hasClass
(
'
error
'
))
{
return
;
}
// Hide the form item container of the machine name form element.
$wrapper
.
hide
();
// Append the machine name preview to the source field.
if
(
$target
.
is
(
'
:disabled
'
))
{
var
machine
=
$target
.
val
();
}
else
{
var
machine
=
self
.
transliterate
(
$source
.
val
(),
options
);
}
var
$preview
=
$
(
'
<span class="machine-name-value">
'
+
machine
+
'
</span>
'
);
$suffix
.
empty
()
.
append
(
'
'
).
append
(
'
<span class="machine-name-label">
'
+
options
.
label
+
'
:</span>
'
)
.
append
(
'
'
).
append
(
$preview
);
// Append a link to edit the machine name, if it is editable, and only if
// one of the following conditions is met:
// - the machine name is empty.
// - the human-readable name is equal to the existing machine name.
if
(
!
$target
.
is
(
'
:disabled
'
)
&&
(
$target
.
val
()
==
''
||
$target
.
val
()
==
machine
))
{
var
$link
=
$
(
'
<span class="admin-link"><a href="#">
'
+
Drupal
.
t
(
'
Edit
'
)
+
'
</a></span>
'
)
.
click
(
function
()
{
$wrapper
.
show
();
$target
.
focus
();
$suffix
.
hide
();
$source
.
unbind
(
'
keyup.machineName
'
);
return
false
;
});
$suffix
.
append
(
'
'
).
append
(
$link
);
// Preview machine name in realtime when the human-readable name changes.
$source
.
bind
(
'
keyup.machineName change.machineName
'
,
function
()
{
machine
=
self
.
transliterate
(
$
(
this
).
val
(),
options
);
// Set the machine name to the transliterated value.
if
(
machine
!=
options
.
replace
&&
machine
!=
''
)
{
$target
.
val
(
machine
);
$preview
.
text
(
machine
);
$suffix
.
show
();
}
else
{
$suffix
.
hide
();
$target
.
val
(
machine
);
$preview
.
empty
();
}
});
// Initialize machine name preview.
$source
.
keyup
();
}
});
},
/**
* Transliterate a human-readable name to a machine name.
*
* @param source
* A string to transliterate.
* @param settings
* The machine name settings for the corresponding field, containing:
* - replace_pattern: A regular expression (without modifiers) matching
* disallowed characters in the machine name; e.g., '[^a-z0-9]+'.
* - replace: A character to replace disallowed characters with; e.g., '_'
* or '-'.
*
* @return
* The transliterated source string.
*/
transliterate
:
function
(
source
,
settings
)
{
var
rx
=
new
RegExp
(
settings
.
replace_pattern
,
'
g
'
);
return
source
.
toLowerCase
().
replace
(
rx
,
settings
.
replace
);
}
};
})(
jQuery
);
This diff is collapsed.
Click to expand it.
modules/system/system.admin.css
+
10
−
0
View file @
e45e8b2a
...
...
@@ -55,6 +55,16 @@ small .admin-link:after {
content
:
']'
;
}
/**
* Quick inline admin links.
*/
small
.admin-link
:before
{
content
:
'['
;
}
small
.admin-link
:after
{
content
:
']'
;
}
/**
* Modules page.
*/
...
...
This diff is collapsed.
Click to expand it.
modules/system/system.module
+
12
−
0
View file @
e45e8b2a
...
...
@@ -359,6 +359,18 @@ function system_element_info() {
'#theme'
=>
'textfield'
,
'#theme_wrappers'
=>
array
(
'form_element'
),
);
$types
[
'machine_name'
]
=
array
(
'#input'
=>
TRUE
,
'#default_value'
=>
NULL
,
'#required'
=>
TRUE
,
'#maxlength'
=>
64
,
'#size'
=>
60
,
'#autocomplete_path'
=>
FALSE
,
'#process'
=>
array
(
'form_process_machine_name'
,
'ajax_process_form'
),
'#element_validate'
=>
array
(
'form_validate_machine_name'
),
'#theme'
=>
'textfield'
,
'#theme_wrappers'
=>
array
(
'form_element'
),
);
$types
[
'password'
]
=
array
(
'#input'
=>
TRUE
,
'#size'
=>
60
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment