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
222
Merge Requests
222
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
8f028bb7
Commit
8f028bb7
authored
Mar 30, 2014
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2225371
by mr.baileys, Wim Leers: Apply formatters and widgets to Custom Block base fields.
parent
d19928b6
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
51 additions
and
41 deletions
+51
-41
core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php
...ock/lib/Drupal/custom_block/CustomBlockFormController.php
+1
-11
core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php
...stom_block/lib/Drupal/custom_block/Entity/CustomBlock.php
+9
-3
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php
...lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php
+13
-13
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php
...ck/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php
+3
-3
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockListTest.php
...ock/lib/Drupal/custom_block/Tests/CustomBlockListTest.php
+2
-2
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTranslationUITest.php
...rupal/custom_block/Tests/CustomBlockTranslationUITest.php
+14
-0
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php
...ock/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php
+5
-5
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php
...stom_block/lib/Drupal/custom_block/Tests/PageEditTest.php
+4
-4
No files found.
core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php
View file @
8f028bb7
...
...
@@ -96,16 +96,6 @@ public function form(array $form, array &$form_state) {
// names.
$form
[
'#attributes'
][
'class'
][
0
]
=
drupal_html_class
(
'block-'
.
$block
->
bundle
()
.
'-form'
);
// Basic block information.
$form
[
'info'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Block description'
),
'#required'
=>
TRUE
,
'#default_value'
=>
$block
->
label
(),
'#weight'
=>
-
5
,
'#description'
=>
$this
->
t
(
'A brief description of your block. Used on the <a href="@overview">Blocks administration page</a>.'
,
array
(
'@overview'
=>
$this
->
url
(
'block.admin_display'
))),
);
if
(
$this
->
moduleHandler
->
moduleExists
(
'language'
))
{
$language_configuration
=
language_get_default_configuration
(
'custom_block'
,
$block
->
bundle
());
...
...
@@ -255,7 +245,7 @@ public function validateForm(array &$form, array &$form_state) {
$exists
=
$this
->
customBlockStorage
->
loadByProperties
(
array
(
'info'
=>
$form_state
[
'values'
][
'info'
]));
if
(
!
empty
(
$exists
))
{
$this
->
setFormError
(
'info'
,
$form_state
,
$this
->
t
(
'A block with description %name already exists.'
,
array
(
'%name'
=>
$form_state
[
'values'
][
'info'
],
'%name'
=>
$form_state
[
'values'
][
'info'
]
[
0
][
'value'
]
,
)));
}
}
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php
View file @
8f028bb7
...
...
@@ -177,9 +177,15 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->
setDescription
(
t
(
'The custom block language code.'
));
$fields
[
'info'
]
=
FieldDefinition
::
create
(
'string'
)
->
setLabel
(
t
(
'Subject'
))
->
setDescription
(
t
(
'The custom block name.'
))
->
setRevisionable
(
TRUE
);
->
setLabel
(
t
(
'Block description'
))
->
setDescription
(
t
(
'A brief description of your block.'
))
->
setRevisionable
(
TRUE
)
->
setRequired
(
TRUE
)
->
setDisplayOptions
(
'form'
,
array
(
'type'
=>
'string'
,
'weight'
=>
-
5
,
))
->
setDisplayConfigurable
(
'form'
,
TRUE
);
$fields
[
'type'
]
=
FieldDefinition
::
create
(
'entity_reference'
)
->
setLabel
(
t
(
'Block type'
))
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php
View file @
8f028bb7
...
...
@@ -60,14 +60,14 @@ public function testCustomBlockCreation() {
// Create a block.
$edit
=
array
();
$edit
[
'info'
]
=
'Test Block'
;
$edit
[
'info
[0][value]
'
]
=
'Test Block'
;
$edit
[
'body[0][value]'
]
=
$this
->
randomName
(
16
);
$this
->
drupalPostForm
(
'block/add/basic'
,
$edit
,
t
(
'Save'
));
// Check that the Basic block has been created.
$this
->
assertRaw
(
format_string
(
'!block %name has been created.'
,
array
(
'!block'
=>
'Basic block'
,
'%name'
=>
$edit
[
"info"
]
'%name'
=>
$edit
[
'info[0][value]'
]
)),
'Basic block created.'
);
// Change the view mode.
...
...
@@ -82,7 +82,7 @@ public function testCustomBlockCreation() {
$this
->
assertOption
(
'edit-settings-custom-block-view-mode'
,
'default'
,
'The default view mode is available.'
);
// Check that the block exists in the database.
$blocks
=
entity_load_multiple_by_properties
(
'custom_block'
,
array
(
'info'
=>
$edit
[
'info'
]));
$blocks
=
entity_load_multiple_by_properties
(
'custom_block'
,
array
(
'info'
=>
$edit
[
'info
[0][value]
'
]));
$block
=
reset
(
$blocks
);
$this
->
assertTrue
(
$block
,
'Custom Block found in database.'
);
...
...
@@ -92,7 +92,7 @@ public function testCustomBlockCreation() {
// Check that the Basic block has been created.
$this
->
assertRaw
(
format_string
(
'A block with description %name already exists.'
,
array
(
'%name'
=>
$edit
[
"info"
]
'%name'
=>
$edit
[
'info[0][value]'
]
)));
$this
->
assertResponse
(
200
);
}
...
...
@@ -105,7 +105,7 @@ public function testCustomBlockCreation() {
*/
public
function
testDefaultCustomBlockCreation
()
{
$edit
=
array
();
$edit
[
'info'
]
=
$this
->
randomName
(
8
);
$edit
[
'info
[0][value]
'
]
=
$this
->
randomName
(
8
);
$edit
[
'body[0][value]'
]
=
$this
->
randomName
(
16
);
// Don't pass the custom block type in the url so the default is forced.
$this
->
drupalPostForm
(
'block/add'
,
$edit
,
t
(
'Save'
));
...
...
@@ -113,11 +113,11 @@ public function testDefaultCustomBlockCreation() {
// Check that the block has been created and that it is a basic block.
$this
->
assertRaw
(
format_string
(
'!block %name has been created.'
,
array
(
'!block'
=>
'Basic block'
,
'%name'
=>
$edit
[
"info"
],
'%name'
=>
$edit
[
'info[0][value]'
],
)),
'Basic block created.'
);
// Check that the block exists in the database.
$blocks
=
entity_load_multiple_by_properties
(
'custom_block'
,
array
(
'info'
=>
$edit
[
'info'
]));
$blocks
=
entity_load_multiple_by_properties
(
'custom_block'
,
array
(
'info'
=>
$edit
[
'info
[0][value]
'
]));
$block
=
reset
(
$blocks
);
$this
->
assertTrue
(
$block
,
'Default Custom Block found in database.'
);
}
...
...
@@ -165,15 +165,15 @@ public function testFailedBlockCreation() {
public
function
testBlockDelete
()
{
// Create a block.
$edit
=
array
();
$edit
[
'info'
]
=
$this
->
randomName
(
8
);
$edit
[
'info
[0][value]
'
]
=
$this
->
randomName
(
8
);
$body
=
$this
->
randomName
(
16
);
$edit
[
'body[0][value]'
]
=
$body
;
$this
->
drupalPostForm
(
'block/add/basic'
,
$edit
,
t
(
'Save'
));
// Place the block.
$instance
=
array
(
'id'
=>
drupal_strtolower
(
$edit
[
'info'
]),
'settings[label]'
=>
$edit
[
'info'
],
'id'
=>
drupal_strtolower
(
$edit
[
'info
[0][value]
'
]),
'settings[label]'
=>
$edit
[
'info
[0][value]
'
],
'region'
=>
'sidebar_first'
,
);
$block
=
entity_load
(
'custom_block'
,
1
);
...
...
@@ -194,11 +194,11 @@ public function testBlockDelete() {
$this
->
assertText
(
format_plural
(
1
,
'This will also remove 1 placed block instance.'
,
'This will also remove @count placed block instance.'
));
$this
->
drupalPostForm
(
NULL
,
array
(),
'Delete'
);
$this
->
assertRaw
(
t
(
'Custom block %name has been deleted.'
,
array
(
'%name'
=>
$edit
[
'info'
])));
$this
->
assertRaw
(
t
(
'Custom block %name has been deleted.'
,
array
(
'%name'
=>
$edit
[
'info
[0][value]
'
])));
// Create another block and force the plugin cache to flush.
$edit2
=
array
();
$edit2
[
'info'
]
=
$this
->
randomName
(
8
);
$edit2
[
'info
[0][value]
'
]
=
$this
->
randomName
(
8
);
$body2
=
$this
->
randomName
(
16
);
$edit2
[
'body[0][value]'
]
=
$body2
;
$this
->
drupalPostForm
(
'block/add/basic'
,
$edit2
,
t
(
'Save'
));
...
...
@@ -208,7 +208,7 @@ public function testBlockDelete() {
// Create another block with no instances, and test we don't get a
// confirmation message about deleting instances.
$edit3
=
array
();
$edit3
[
'info'
]
=
$this
->
randomName
(
8
);
$edit3
[
'info
[0][value]
'
]
=
$this
->
randomName
(
8
);
$body
=
$this
->
randomName
(
16
);
$edit3
[
'body[0][value]'
]
=
$body
;
$this
->
drupalPostForm
(
'block/add/basic'
,
$edit3
,
t
(
'Save'
));
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php
View file @
8f028bb7
...
...
@@ -95,7 +95,7 @@ public function testBlockFields() {
// Create a block.
$this
->
drupalGet
(
'block/add/link'
);
$edit
=
array
(
'info'
=>
$this
->
randomName
(
8
),
'info
[0][value]
'
=>
$this
->
randomName
(
8
),
$this
->
field
->
getName
()
.
'[0][url]'
=>
'http://example.com'
,
$this
->
field
->
getName
()
.
'[0][title]'
=>
'Example.com'
);
...
...
@@ -104,8 +104,8 @@ public function testBlockFields() {
$url
=
'admin/structure/block/add/custom_block:'
.
$block
->
uuid
()
.
'/'
.
\
Drupal
::
config
(
'system.theme'
)
->
get
(
'default'
);
// Place the block.
$instance
=
array
(
'id'
=>
drupal_strtolower
(
$edit
[
'info'
]),
'settings[label]'
=>
$edit
[
'info'
],
'id'
=>
drupal_strtolower
(
$edit
[
'info
[0][value]
'
]),
'settings[label]'
=>
$edit
[
'info
[0][value]
'
],
'region'
=>
'sidebar_first'
,
);
$this
->
drupalPostForm
(
$url
,
$instance
,
t
(
'Save block'
));
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockListTest.php
View file @
8f028bb7
...
...
@@ -63,7 +63,7 @@ public function testListing() {
$this
->
clickLink
(
$link_text
);
$this
->
assertResponse
(
200
);
$edit
=
array
();
$edit
[
'info'
]
=
$label
;
$edit
[
'info
[0][value]
'
]
=
$label
;
$edit
[
'body[0][value]'
]
=
$this
->
randomName
(
16
);
$this
->
drupalPostForm
(
NULL
,
$edit
,
t
(
'Save'
));
...
...
@@ -90,7 +90,7 @@ public function testListing() {
$this
->
clickLink
(
t
(
'Edit'
));
$this
->
assertResponse
(
200
);
$this
->
assertTitle
(
strip_tags
(
t
(
'Edit custom block %label'
,
array
(
'%label'
=>
$label
))
.
' | Drupal'
));
$edit
=
array
(
'info'
=>
$new_label
);
$edit
=
array
(
'info
[0][value]
'
=>
$new_label
);
$this
->
drupalPostForm
(
NULL
,
$edit
,
t
(
'Save'
));
}
else
{
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTranslationUITest.php
View file @
8f028bb7
...
...
@@ -99,6 +99,20 @@ protected function getNewEntityValues($langcode) {
return
array
(
'info'
=>
$this
->
name
)
+
parent
::
getNewEntityValues
(
$langcode
);
}
/**
* Returns an edit array containing the values to be posted.
*/
protected
function
getEditValues
(
$values
,
$langcode
,
$new
=
FALSE
)
{
$edit
=
parent
::
getEditValues
(
$values
,
$langcode
,
$new
);
foreach
(
$edit
as
$property
=>
$value
)
{
if
(
$property
==
'info'
)
{
$edit
[
'info[0][value]'
]
=
$value
;
unset
(
$edit
[
$property
]);
}
}
return
$edit
;
}
/**
* Test that no metadata is stored for a disabled bundle.
*/
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php
View file @
8f028bb7
...
...
@@ -178,15 +178,15 @@ public function testsCustomBlockAddTypes() {
$this
->
clickLink
(
'foo'
);
}
// Create a new block.
$edit
=
array
(
'info'
=>
$this
->
randomName
(
8
));
$edit
=
array
(
'info
[0][value]
'
=>
$this
->
randomName
(
8
));
$this
->
drupalPostForm
(
NULL
,
$edit
,
t
(
'Save'
));
$blocks
=
$storage
->
loadByProperties
(
array
(
'info'
=>
$edit
[
'info'
]));
$blocks
=
$storage
->
loadByProperties
(
array
(
'info'
=>
$edit
[
'info
[0][value]
'
]));
if
(
!
empty
(
$blocks
))
{
$block
=
reset
(
$blocks
);
$destination
=
'admin/structure/block/add/custom_block:'
.
$block
->
uuid
()
.
'/'
.
$theme
;
$this
->
assertUrl
(
url
(
$destination
,
array
(
'absolute'
=>
TRUE
)));
$this
->
drupalPostForm
(
NULL
,
array
(),
t
(
'Save block'
));
$this
->
assertUrl
(
url
(
"admin/structure/block/list/
$theme
"
,
array
(
'absolute'
=>
TRUE
,
'query'
=>
array
(
'block-placement'
=>
drupal_html_class
(
$edit
[
'info'
])))));
$this
->
assertUrl
(
url
(
"admin/structure/block/list/
$theme
"
,
array
(
'absolute'
=>
TRUE
,
'query'
=>
array
(
'block-placement'
=>
drupal_html_class
(
$edit
[
'info
[0][value]
'
])))));
}
else
{
$this
->
fail
(
'Could not load created block.'
);
...
...
@@ -199,9 +199,9 @@ public function testsCustomBlockAddTypes() {
$this
->
drupalGet
(
'admin/structure/block/custom-blocks'
);
$this
->
clickLink
(
t
(
'Add custom block'
));
$this
->
clickLink
(
'foo'
);
$edit
=
array
(
'info'
=>
$this
->
randomName
(
8
));
$edit
=
array
(
'info
[0][value]
'
=>
$this
->
randomName
(
8
));
$this
->
drupalPostForm
(
NULL
,
$edit
,
t
(
'Save'
));
$blocks
=
$storage
->
loadByProperties
(
array
(
'info'
=>
$edit
[
'info'
]));
$blocks
=
$storage
->
loadByProperties
(
array
(
'info'
=>
$edit
[
'info
[0][value]
'
]));
if
(
!
empty
(
$blocks
))
{
$destination
=
'admin/structure/block/custom-blocks'
;
$this
->
assertUrl
(
url
(
$destination
,
array
(
'absolute'
=>
TRUE
)));
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php
View file @
8f028bb7
...
...
@@ -31,16 +31,16 @@ public static function getInfo() {
public
function
testPageEdit
()
{
$this
->
drupalLogin
(
$this
->
adminUser
);
$title_key
=
'info'
;
$title_key
=
'info
[0][value]
'
;
$body_key
=
'body[0][value]'
;
// Create block to edit.
$edit
=
array
();
$edit
[
'info'
]
=
drupal_strtolower
(
$this
->
randomName
(
8
));
$edit
[
'info
[0][value]
'
]
=
drupal_strtolower
(
$this
->
randomName
(
8
));
$edit
[
$body_key
]
=
$this
->
randomName
(
16
);
$this
->
drupalPostForm
(
'block/add/basic'
,
$edit
,
t
(
'Save'
));
// Check that the block exists in the database.
$blocks
=
\
Drupal
::
entityQuery
(
'custom_block'
)
->
condition
(
'info'
,
$edit
[
'info'
])
->
execute
();
$blocks
=
\
Drupal
::
entityQuery
(
'custom_block'
)
->
condition
(
'info'
,
$edit
[
'info
[0][value]
'
])
->
execute
();
$block
=
entity_load
(
'custom_block'
,
reset
(
$blocks
));
$this
->
assertTrue
(
$block
,
'Custom block found in database.'
);
...
...
@@ -59,7 +59,7 @@ public function testPageEdit() {
// Edit the same block, creating a new revision.
$this
->
drupalGet
(
"block/"
.
$block
->
id
());
$edit
=
array
();
$edit
[
'info'
]
=
$this
->
randomName
(
8
);
$edit
[
'info
[0][value]
'
]
=
$this
->
randomName
(
8
);
$edit
[
$body_key
]
=
$this
->
randomName
(
16
);
$edit
[
'revision'
]
=
TRUE
;
$this
->
drupalPostForm
(
NULL
,
$edit
,
t
(
'Save'
));
...
...
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