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
310
Merge Requests
310
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
1b186cf0
Unverified
Commit
1b186cf0
authored
Nov 08, 2018
by
larowlan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#3008772
by andypost, tim.plunkett: Layout definition defined in YAML is not translated
parent
729b4406
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
13 deletions
+50
-13
core/lib/Drupal/Core/Layout/LayoutPluginManager.php
core/lib/Drupal/Core/Layout/LayoutPluginManager.php
+14
-0
core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php
...ests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php
+36
-13
No files found.
core/lib/Drupal/Core/Layout/LayoutPluginManager.php
View file @
1b186cf0
...
...
@@ -13,6 +13,7 @@
use
Drupal\Core\Plugin\Discovery\YamlDiscoveryDecorator
;
use
Drupal\Core\Layout\Annotation\Layout
;
use
Drupal\Core\Plugin\FilteredPluginManagerTrait
;
use
Drupal\Core\StringTranslation\TranslatableMarkup
;
/**
* Provides a plugin manager for layouts.
...
...
@@ -71,6 +72,10 @@ protected function getDiscovery() {
if
(
!
$this
->
discovery
)
{
$discovery
=
new
AnnotatedClassDiscovery
(
$this
->
subdir
,
$this
->
namespaces
,
$this
->
pluginDefinitionAnnotationName
,
$this
->
additionalAnnotationNamespaces
);
$discovery
=
new
YamlDiscoveryDecorator
(
$discovery
,
'layouts'
,
$this
->
moduleHandler
->
getModuleDirectories
()
+
$this
->
themeHandler
->
getThemeDirectories
());
$discovery
->
addTranslatableProperty
(
'label'
)
->
addTranslatableProperty
(
'description'
)
->
addTranslatableProperty
(
'category'
);
$discovery
=
new
AnnotationBridgeDecorator
(
$discovery
,
$this
->
pluginDefinitionAnnotationName
);
$discovery
=
new
ContainerDerivativeDiscoveryDecorator
(
$discovery
);
$this
->
discovery
=
$discovery
;
...
...
@@ -140,6 +145,15 @@ public function processDefinition(&$definition, $plugin_id) {
if
(
!
$definition
->
getDefaultRegion
())
{
$definition
->
setDefaultRegion
(
key
(
$definition
->
getRegions
()));
}
// Makes sure region names are translatable.
$regions
=
array_map
(
function
(
$region
)
{
if
(
!
$region
[
'label'
]
instanceof
TranslatableMarkup
)
{
// Region labels from YAML discovery needs translation.
$region
[
'label'
]
=
new
TranslatableMarkup
(
$region
[
'label'
],
[],
[
'context'
=>
'layout_region'
]);
}
return
$region
;
},
$definition
->
getRegions
());
$definition
->
setRegions
(
$regions
);
}
/**
...
...
core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php
View file @
1b186cf0
...
...
@@ -12,6 +12,7 @@
use
Drupal\Core\Layout\LayoutDefault
;
use
Drupal\Core\Layout\LayoutDefinition
;
use
Drupal\Core\Layout\LayoutPluginManager
;
use
Drupal\Core\StringTranslation\TranslatableMarkup
;
use
Drupal\Tests\UnitTestCase
;
use
org\bovigo\vfs\vfsStream
;
use
Prophecy\Argument
;
...
...
@@ -114,8 +115,12 @@ public function testGetDefinition() {
$theme_a_path
=
vfsStream
::
url
(
'root/themes/theme_a'
);
$layout_definition
=
$this
->
layoutPluginManager
->
getDefinition
(
'theme_a_provided_layout'
);
$this
->
assertSame
(
'theme_a_provided_layout'
,
$layout_definition
->
id
());
$this
->
assertSame
(
'2 column layout'
,
$layout_definition
->
getLabel
());
$this
->
assertSame
(
'Columns: 2'
,
$layout_definition
->
getCategory
());
$this
->
assertSame
(
'2 column layout'
,
(
string
)
$layout_definition
->
getLabel
());
$this
->
assertSame
(
'Columns: 2'
,
(
string
)
$layout_definition
->
getCategory
());
$this
->
assertSame
(
'A theme provided layout'
,
(
string
)
$layout_definition
->
getDescription
());
$this
->
assertTrue
(
$layout_definition
->
getLabel
()
instanceof
TranslatableMarkup
);
$this
->
assertTrue
(
$layout_definition
->
getCategory
()
instanceof
TranslatableMarkup
);
$this
->
assertTrue
(
$layout_definition
->
getDescription
()
instanceof
TranslatableMarkup
);
$this
->
assertSame
(
'twocol'
,
$layout_definition
->
getTemplate
());
$this
->
assertSame
(
"
$theme_a_path
/templates"
,
$layout_definition
->
getPath
());
$this
->
assertSame
(
'theme_a/twocol'
,
$layout_definition
->
getLibrary
());
...
...
@@ -126,19 +131,26 @@ public function testGetDefinition() {
$this
->
assertSame
(
LayoutDefault
::
class
,
$layout_definition
->
getClass
());
$expected_regions
=
[
'left'
=>
[
'label'
=>
'Left region'
,
'label'
=>
new
TranslatableMarkup
(
'Left region'
,
[],
[
'context'
=>
'layout_region'
])
,
],
'right'
=>
[
'label'
=>
'Right region'
,
'label'
=>
new
TranslatableMarkup
(
'Right region'
,
[],
[
'context'
=>
'layout_region'
])
,
],
];
$this
->
assertSame
(
$expected_regions
,
$layout_definition
->
getRegions
());
$regions
=
$layout_definition
->
getRegions
();
$this
->
assertEquals
(
$expected_regions
,
$regions
);
$this
->
assertTrue
(
$regions
[
'left'
][
'label'
]
instanceof
TranslatableMarkup
);
$this
->
assertTrue
(
$regions
[
'right'
][
'label'
]
instanceof
TranslatableMarkup
);
$module_a_path
=
vfsStream
::
url
(
'root/modules/module_a'
);
$layout_definition
=
$this
->
layoutPluginManager
->
getDefinition
(
'module_a_provided_layout'
);
$this
->
assertSame
(
'module_a_provided_layout'
,
$layout_definition
->
id
());
$this
->
assertSame
(
'1 column layout'
,
$layout_definition
->
getLabel
());
$this
->
assertSame
(
'Columns: 1'
,
$layout_definition
->
getCategory
());
$this
->
assertSame
(
'1 column layout'
,
(
string
)
$layout_definition
->
getLabel
());
$this
->
assertSame
(
'Columns: 1'
,
(
string
)
$layout_definition
->
getCategory
());
$this
->
assertSame
(
'A module provided layout'
,
(
string
)
$layout_definition
->
getDescription
());
$this
->
assertTrue
(
$layout_definition
->
getLabel
()
instanceof
TranslatableMarkup
);
$this
->
assertTrue
(
$layout_definition
->
getCategory
()
instanceof
TranslatableMarkup
);
$this
->
assertTrue
(
$layout_definition
->
getDescription
()
instanceof
TranslatableMarkup
);
$this
->
assertSame
(
NULL
,
$layout_definition
->
getTemplate
());
$this
->
assertSame
(
"
$module_a_path
/layouts"
,
$layout_definition
->
getPath
());
$this
->
assertSame
(
'module_a/onecol'
,
$layout_definition
->
getLibrary
());
...
...
@@ -149,19 +161,26 @@ public function testGetDefinition() {
$this
->
assertSame
(
LayoutDefault
::
class
,
$layout_definition
->
getClass
());
$expected_regions
=
[
'top'
=>
[
'label'
=>
'Top region'
,
'label'
=>
new
TranslatableMarkup
(
'Top region'
,
[],
[
'context'
=>
'layout_region'
])
,
],
'bottom'
=>
[
'label'
=>
'Bottom region'
,
'label'
=>
new
TranslatableMarkup
(
'Bottom region'
,
[],
[
'context'
=>
'layout_region'
])
,
],
];
$this
->
assertSame
(
$expected_regions
,
$layout_definition
->
getRegions
());
$regions
=
$layout_definition
->
getRegions
();
$this
->
assertEquals
(
$expected_regions
,
$regions
);
$this
->
assertTrue
(
$regions
[
'top'
][
'label'
]
instanceof
TranslatableMarkup
);
$this
->
assertTrue
(
$regions
[
'bottom'
][
'label'
]
instanceof
TranslatableMarkup
);
$core_path
=
'/core/lib/Drupal/Core'
;
$layout_definition
=
$this
->
layoutPluginManager
->
getDefinition
(
'plugin_provided_layout'
);
$this
->
assertSame
(
'plugin_provided_layout'
,
$layout_definition
->
id
());
$this
->
assertEquals
(
'Layout plugin'
,
$layout_definition
->
getLabel
());
$this
->
assertEquals
(
'Columns: 1'
,
$layout_definition
->
getCategory
());
$this
->
assertEquals
(
'Test layout'
,
$layout_definition
->
getDescription
());
$this
->
assertTrue
(
$layout_definition
->
getLabel
()
instanceof
TranslatableMarkup
);
$this
->
assertTrue
(
$layout_definition
->
getCategory
()
instanceof
TranslatableMarkup
);
$this
->
assertTrue
(
$layout_definition
->
getDescription
()
instanceof
TranslatableMarkup
);
$this
->
assertSame
(
'plugin-provided-layout'
,
$layout_definition
->
getTemplate
());
$this
->
assertSame
(
$core_path
,
$layout_definition
->
getPath
());
$this
->
assertSame
(
NULL
,
$layout_definition
->
getLibrary
());
...
...
@@ -172,10 +191,12 @@ public function testGetDefinition() {
$this
->
assertSame
(
'Drupal\Core\Plugin\Layout\TestLayout'
,
$layout_definition
->
getClass
());
$expected_regions
=
[
'main'
=>
[
'label'
=>
'Main Region'
,
'label'
=>
new
TranslatableMarkup
(
'Main Region'
,
[],
[
'context'
=>
'layout_region'
])
,
],
];
$this
->
assertEquals
(
$expected_regions
,
$layout_definition
->
getRegions
());
$regions
=
$layout_definition
->
getRegions
();
$this
->
assertEquals
(
$expected_regions
,
$regions
);
$this
->
assertTrue
(
$regions
[
'main'
][
'label'
]
instanceof
TranslatableMarkup
);
}
/**
...
...
@@ -284,6 +305,7 @@ protected function setUpFilesystem() {
module_a_provided_layout:
label: 1 column layout
category: 'Columns: 1'
description: 'A module provided layout'
theme_hook: onecol
path: layouts
library: module_a/onecol
...
...
@@ -301,6 +323,7 @@ protected function setUpFilesystem() {
class: '\Drupal\Core\Layout\LayoutDefault'
label: 2 column layout
category: 'Columns: 2'
description: 'A theme provided layout'
template: twocol
path: templates
library: theme_a/twocol
...
...
@@ -325,7 +348,7 @@ class: '\Drupal\Core\Layout\LayoutDefault'
* template = "templates/plugin-provided-layout",
* regions = {
* "main" = {
* "label" = @Translation("Main Region")
* "label" = @Translation("Main Region"
, context = "layout_region"
)
* }
* }
* )
...
...
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