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
1b186cf0
Verified
Commit
1b186cf0
authored
6 years ago
by
Lee Rowlands
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3008772
by andypost, tim.plunkett: Layout definition defined in YAML is not translated
parent
729b4406
Branches
Branches containing commit
Tags
Tags containing commit
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
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib/Drupal/Core/Layout/LayoutPluginManager.php
+14
-0
14 additions, 0 deletions
core/lib/Drupal/Core/Layout/LayoutPluginManager.php
core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php
+36
-13
36 additions, 13 deletions
...ests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php
with
50 additions
and
13 deletions
core/lib/Drupal/Core/Layout/LayoutPluginManager.php
+
14
−
0
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
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php
+
36
−
13
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"
)
* }
* }
* )
...
...
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