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
225
Merge Requests
225
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
42083a1c
Commit
42083a1c
authored
Feb 08, 2015
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2414721
by jesperjb, plach: EntityAdapter should be instantiated per language
parent
91ae64ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
core/lib/Drupal/Core/Entity/ContentEntityBase.php
core/lib/Drupal/Core/Entity/ContentEntityBase.php
+2
-2
core/modules/system/src/Tests/Entity/EntityTranslationTest.php
...modules/system/src/Tests/Entity/EntityTranslationTest.php
+25
-0
No files found.
core/lib/Drupal/Core/Entity/ContentEntityBase.php
View file @
42083a1c
...
@@ -650,9 +650,9 @@ protected function initializeTranslation($langcode) {
...
@@ -650,9 +650,9 @@ protected function initializeTranslation($langcode) {
$translation
->
translations
=
&
$this
->
translations
;
$translation
->
translations
=
&
$this
->
translations
;
$translation
->
enforceIsNew
=
&
$this
->
enforceIsNew
;
$translation
->
enforceIsNew
=
&
$this
->
enforceIsNew
;
$translation
->
translationInitialize
=
FALSE
;
$translation
->
translationInitialize
=
FALSE
;
// The label is the only entity key that can change based on the language,
// Reset language-dependent properties.
// so unset that in case it is currently set.
unset
(
$translation
->
entityKeys
[
'label'
]);
unset
(
$translation
->
entityKeys
[
'label'
]);
$translation
->
typedData
=
NULL
;
return
$translation
;
return
$translation
;
}
}
...
...
core/modules/system/src/Tests/Entity/EntityTranslationTest.php
View file @
42083a1c
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
namespace
Drupal\system\Tests\Entity
;
namespace
Drupal\system\Tests\Entity
;
use
Drupal\Component\Utility\String
;
use
Drupal\Core\Language\LanguageInterface
;
use
Drupal\Core\Language\LanguageInterface
;
use
Drupal\entity_test
\
Entity\EntityTestMulRev
;
use
Drupal\entity_test
\
Entity\EntityTestMulRev
;
use
Drupal\language\Entity\ConfigurableLanguage
;
use
Drupal\language\Entity\ConfigurableLanguage
;
...
@@ -665,4 +666,28 @@ protected function doTestLanguageChange($entity_type) {
...
@@ -665,4 +666,28 @@ protected function doTestLanguageChange($entity_type) {
}
}
}
}
/**
* Tests how entity adapters work with translations.
*/
function
testEntityAdapter
()
{
$entity_type
=
'entity_test'
;
$default_langcode
=
'en'
;
$values
[
$default_langcode
]
=
array
(
'name'
=>
$this
->
randomString
());
$controller
=
$this
->
entityManager
->
getStorage
(
$entity_type
);
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity
=
$controller
->
create
(
$values
[
$default_langcode
]);
foreach
(
$this
->
langcodes
as
$langcode
)
{
$values
[
$langcode
]
=
array
(
'name'
=>
$this
->
randomString
());
$entity
->
addTranslation
(
$langcode
,
$values
[
$langcode
]);
}
$langcodes
=
array_merge
(
array
(
$default_langcode
),
$this
->
langcodes
);
foreach
(
$langcodes
as
$langcode
)
{
$adapter
=
$entity
->
getTranslation
(
$langcode
)
->
getTypedData
();
$name
=
$adapter
->
get
(
'name'
)
->
value
;
$this
->
assertEqual
(
$name
,
$values
[
$langcode
][
'name'
],
String
::
format
(
'Name correctly retrieved from "@langcode" adapter'
,
array
(
'@langcode'
=>
$langcode
)));
}
}
}
}
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