Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
2b24e721
Commit
2b24e721
authored
Aug 25, 2014
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2183929
by cilefen, tim.plunkett: Allow \Drupal:: call in BlockBase to be bypassed.
parent
8e3819bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
+33
-3
core/lib/Drupal/Core/Block/BlockBase.php
core/lib/Drupal/Core/Block/BlockBase.php
+31
-2
core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php
core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php
+2
-1
No files found.
core/lib/Drupal/Core/Block/BlockBase.php
View file @
2b24e721
...
...
@@ -21,6 +21,7 @@
use
Drupal\Core\Language\LanguageInterface
;
use
Drupal\Core\Cache\Cache
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\Component\Transliteration\TransliterationInterface
;
/**
* Defines a base block implementation that most blocks plugins will extend.
...
...
@@ -49,6 +50,13 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn
*/
protected
$conditionPluginManager
;
/**
* The transliteration service.
*
* @var \Drupal\Component\Transliteration\TransliterationInterface
*/
protected
$transliteration
;
/**
* {@inheritdoc}
*/
...
...
@@ -407,8 +415,7 @@ public function getMachineNameSuggestion() {
// @todo This is basically the same as what is done in
// \Drupal\system\MachineNameController::transliterate(), so it might make
// sense to provide a common service for the two.
$transliteration_service
=
\
Drupal
::
transliteration
();
$transliterated
=
$transliteration_service
->
transliterate
(
$admin_label
,
LanguageInterface
::
LANGCODE_DEFAULT
,
'_'
);
$transliterated
=
$this
->
transliteration
()
->
transliterate
(
$admin_label
,
LanguageInterface
::
LANGCODE_DEFAULT
,
'_'
);
$replace_pattern
=
'[^a-z0-9_.]+'
;
...
...
@@ -421,6 +428,28 @@ public function getMachineNameSuggestion() {
return
$transliterated
;
}
/**
* Wraps the transliteration service.
*
* @return \Drupal\Component\Transliteration\TransliterationInterface
*/
protected
function
transliteration
()
{
if
(
!
$this
->
transliteration
)
{
$this
->
transliteration
=
\
Drupal
::
transliteration
();
}
return
$this
->
transliteration
;
}
/**
* Sets the transliteration service.
*
* @param \Drupal\Component\Transliteration\TransliterationInterface $transliteration
* The transliteration service.
*/
public
function
setTransliteration
(
TransliterationInterface
$transliteration
)
{
$this
->
transliteration
=
$transliteration
;
}
/**
* Returns the cache contexts required for this block.
*
...
...
core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php
View file @
2b24e721
...
...
@@ -34,7 +34,6 @@ public function testGetMachineNameSuggestion() {
->
will
(
$this
->
returnValue
(
array
()));
$container
=
new
ContainerBuilder
();
$container
->
set
(
'plugin.manager.condition'
,
$condition_plugin_manager
);
$container
->
set
(
'transliteration'
,
$transliteraton
);
\
Drupal
::
setContainer
(
$container
);
$config
=
array
();
...
...
@@ -43,6 +42,7 @@ public function testGetMachineNameSuggestion() {
'provider'
=>
'block_test'
,
);
$block_base
=
new
TestBlockInstantiation
(
$config
,
'test_block_instantiation'
,
$definition
);
$block_base
->
setTransliteration
(
$transliteraton
);
$this
->
assertEquals
(
'adminlabel'
,
$block_base
->
getMachineNameSuggestion
());
// Test with more unicodes.
...
...
@@ -51,6 +51,7 @@ public function testGetMachineNameSuggestion() {
'provider'
=>
'block_test'
,
);
$block_base
=
new
TestBlockInstantiation
(
$config
,
'test_block_instantiation'
,
$definition
);
$block_base
->
setTransliteration
(
$transliteraton
);
$this
->
assertEquals
(
'uberawesome'
,
$block_base
->
getMachineNameSuggestion
());
}
...
...
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