Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
221
Merge Requests
221
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
956b110a
Commit
956b110a
authored
Jan 19, 2013
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1884762
by tim.plunkett, Gábor Hojtsy: Block forms should use #type => machine_name().
parent
0143d50f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
14 deletions
+13
-14
core/modules/block/lib/Drupal/block/BlockBase.php
core/modules/block/lib/Drupal/block/BlockBase.php
+6
-7
core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php
...odules/block/lib/Drupal/block/Tests/BlockLanguageTest.php
+1
-1
core/modules/block/lib/Drupal/block/Tests/BlockTest.php
core/modules/block/lib/Drupal/block/Tests/BlockTest.php
+6
-6
No files found.
core/modules/block/lib/Drupal/block/BlockBase.php
View file @
956b110a
...
...
@@ -241,11 +241,15 @@ public function form($form, &$form_state) {
'#default_value'
=>
!
$entity
->
isNew
()
?
$entity
->
label
()
:
$definition
[
'subject'
],
);
$form
[
'machine_name'
]
=
array
(
'#type'
=>
'
textfield
'
,
'#type'
=>
'
machine_name
'
,
'#title'
=>
t
(
'Block machine name'
),
'#maxlength'
=>
64
,
'#description'
=>
t
(
'A unique name to save this block configuration. Must be alpha-numeric and be underscore separated.'
),
'#default_value'
=>
$entity
->
id
(),
'#machine_name'
=>
array
(
'exists'
=>
'block_load'
,
'replace_pattern'
=>
'[^a-z0-9_.]+'
,
),
'#required'
=>
TRUE
,
'#disabled'
=>
!
$entity
->
isNew
(),
);
...
...
@@ -419,12 +423,7 @@ public function blockForm($form, &$form_state) {
* @see \Drupal\block\BlockBase::blockValidate()
*/
public
function
validate
(
$form
,
&
$form_state
)
{
if
(
empty
(
$form
[
'machine_name'
][
'#disabled'
]))
{
if
(
preg_match
(
'/[^a-zA-Z0-9_]/'
,
$form_state
[
'values'
][
'machine_name'
]))
{
form_set_error
(
'machine_name'
,
t
(
'Block name must be alphanumeric or underscores only.'
));
}
}
else
{
if
(
!
empty
(
$form
[
'machine_name'
][
'#disabled'
]))
{
$config_id
=
explode
(
'.'
,
$form_state
[
'values'
][
'machine_name'
]);
$form_state
[
'values'
][
'machine_name'
]
=
array_pop
(
$config_id
);
}
...
...
core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php
View file @
956b110a
...
...
@@ -62,7 +62,7 @@ public function testLanguageBlockVisibility() {
// Enable a standard block and set the visibility setting for one language.
$edit
=
array
(
'visibility[language][langcodes][en]'
=>
TRUE
,
'machine_name'
=>
$this
->
randomName
(
8
),
'machine_name'
=>
strtolower
(
$this
->
randomName
(
8
)
),
'region'
=>
'sidebar_first'
,
);
$this
->
drupalPost
(
'admin/structure/block/add/system_powered_by_block'
.
'/'
.
$default_theme
,
$edit
,
t
(
'Save block'
));
...
...
core/modules/block/lib/Drupal/block/Tests/BlockTest.php
View file @
956b110a
...
...
@@ -157,7 +157,7 @@ public function testCustomBlockFormat() {
$this
->
removeDefaultBlocks
();
// Add a new custom block by filling out the input form on the admin/structure/block/add page.
$info
=
$this
->
randomName
(
8
);
$info
=
strtolower
(
$this
->
randomName
(
8
)
);
$custom_block
[
'machine_name'
]
=
$info
;
$custom_block
[
'info'
]
=
$info
;
$custom_block
[
'label'
]
=
$this
->
randomName
(
8
);
...
...
@@ -199,7 +199,7 @@ function testBlockVisibility() {
// Enable a standard block.
$default_theme
=
variable_get
(
'theme_default'
,
'stark'
);
$edit
=
array
(
'machine_name'
=>
$this
->
randomName
(
8
),
'machine_name'
=>
strtolower
(
$this
->
randomName
(
8
)
),
'region'
=>
'sidebar_first'
,
'label'
=>
$title
,
);
...
...
@@ -239,7 +239,7 @@ function testBlockVisibilityListedEmpty() {
// Enable a standard block.
$default_theme
=
variable_get
(
'theme_default'
,
'stark'
);
$edit
=
array
(
'machine_name'
=>
$this
->
randomName
(
8
),
'machine_name'
=>
strtolower
(
$this
->
randomName
(
8
)
),
'region'
=>
'sidebar_first'
,
'label'
=>
$title
,
'visibility[path][visibility]'
=>
BLOCK_VISIBILITY_LISTED
,
...
...
@@ -270,7 +270,7 @@ function testBlock() {
$block
=
array
();
$block
[
'id'
]
=
'system_powered_by_block'
;
$block
[
'label'
]
=
$this
->
randomName
(
8
);
$block
[
'machine_name'
]
=
$this
->
randomName
(
8
);
$block
[
'machine_name'
]
=
strtolower
(
$this
->
randomName
(
8
)
);
$block
[
'theme'
]
=
variable_get
(
'theme_default'
,
'stark'
);
$block
[
'region'
]
=
'header'
;
...
...
@@ -351,7 +351,7 @@ function testBlockRehash() {
// Add a test block.
$block
=
array
();
$block
[
'id'
]
=
'test_cache'
;
$block
[
'machine_name'
]
=
$this
->
randomName
(
8
);
$block
[
'machine_name'
]
=
strtolower
(
$this
->
randomName
(
8
)
);
$block
[
'theme'
]
=
variable_get
(
'theme_default'
,
'stark'
);
$block
[
'region'
]
=
'header'
;
$block
=
$this
->
drupalPlaceBlock
(
'test_cache'
,
array
(
'region'
=>
'header'
));
...
...
@@ -427,7 +427,7 @@ function testBlockModuleDisable() {
// that the form still functions as expected.
$edit
=
array
(
'label'
=>
$this
->
randomName
(
8
),
'machine_name'
=>
$this
->
randomName
(
8
),
'machine_name'
=>
strtolower
(
$this
->
randomName
(
8
)
),
'region'
=>
'sidebar_first'
,
);
$this
->
drupalPost
(
'admin/structure/block/add/system_powered_by_block/stark'
,
$edit
,
t
(
'Save block'
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment