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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
42083a1c
Commit
42083a1c
authored
Feb 8, 2015
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2414721
by jesperjb, plach: EntityAdapter should be instantiated per language
parent
91ae64ac
No related branches found
No related tags found
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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib/Drupal/Core/Entity/ContentEntityBase.php
+2
-2
2 additions, 2 deletions
core/lib/Drupal/Core/Entity/ContentEntityBase.php
core/modules/system/src/Tests/Entity/EntityTranslationTest.php
+25
-0
25 additions, 0 deletions
...modules/system/src/Tests/Entity/EntityTranslationTest.php
with
27 additions
and
2 deletions
core/lib/Drupal/Core/Entity/ContentEntityBase.php
+
2
−
2
View file @
42083a1c
...
...
@@ -650,9 +650,9 @@ protected function initializeTranslation($langcode) {
$translation
->
translations
=
&
$this
->
translations
;
$translation
->
enforceIsNew
=
&
$this
->
enforceIsNew
;
$translation
->
translationInitialize
=
FALSE
;
// The label is the only entity key that can change based on the language,
// so unset that in case it is currently set.
// Reset language-dependent properties.
unset
(
$translation
->
entityKeys
[
'label'
]);
$translation
->
typedData
=
NULL
;
return
$translation
;
}
...
...
This diff is collapsed.
Click to expand it.
core/modules/system/src/Tests/Entity/EntityTranslationTest.php
+
25
−
0
View file @
42083a1c
...
...
@@ -7,6 +7,7 @@
namespace
Drupal\system\Tests\Entity
;
use
Drupal\Component\Utility\String
;
use
Drupal\Core\Language\LanguageInterface
;
use
Drupal\entity_test
\Entity\EntityTestMulRev
;
use
Drupal\language\Entity\ConfigurableLanguage
;
...
...
@@ -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
)));
}
}
}
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