Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
layout_paragraphs
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
layout_paragraphs
Commits
f29bb968
Commit
f29bb968
authored
3 years ago
by
Julian Pustkuchen
Committed by
Justin Toupin
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3263594
: Incorrect handling of untranslatable (layout) paragraphs in...
Issue
#3263594
: Incorrect handling of untranslatable (layout) paragraphs in translatable environment
parent
5bce2e47
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!103
Issue #3295875: Add a new dedicated permission for Layout paragraphs configurations
,
!64
Issue #3263594: Incorrect handling of untranslatable (layout) paragraphs in translatable environment
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Element/LayoutParagraphsBuilder.php
+20
-17
20 additions, 17 deletions
src/Element/LayoutParagraphsBuilder.php
with
20 additions
and
17 deletions
src/Element/LayoutParagraphsBuilder.php
+
20
−
17
View file @
f29bb968
...
@@ -617,52 +617,55 @@ class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryP
...
@@ -617,52 +617,55 @@ class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryP
/** @var \Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem $item */
/** @var \Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem $item */
foreach
(
$items
as
$delta
=>
$item
)
{
foreach
(
$items
as
$delta
=>
$item
)
{
if
(
!
empty
(
$item
->
entity
)
&&
$item
->
entity
instanceof
ParagraphInterface
)
{
if
(
!
empty
(
$item
->
entity
)
&&
$item
->
entity
instanceof
ParagraphInterface
)
{
// Now we're sure it's a paragraph:
$paragraph
=
$item
->
entity
;
if
(
!
$this
->
isTranslating
())
{
if
(
!
$this
->
isTranslating
())
{
// Set the langcode if we are not translating.
// Set the langcode if we are not translating.
$langcode_key
=
$
item
->
entity
->
getEntityType
()
->
getKey
(
'langcode'
);
$langcode_key
=
$
paragraph
->
getEntityType
()
->
getKey
(
'langcode'
);
if
(
$
item
->
entity
->
get
(
$langcode_key
)
->
value
!=
$this
->
langcode
)
{
if
(
$
paragraph
->
get
(
$langcode_key
)
->
value
!=
$this
->
langcode
)
{
// If a translation in the given language already exists,
// If a translation in the given language already exists,
// switch to that. If there is none yet, update the language.
// switch to that. If there is none yet, update the language.
if
(
$
item
->
entity
->
hasTranslation
(
$this
->
langcode
))
{
if
(
$
paragraph
->
hasTranslation
(
$this
->
langcode
))
{
$
item
->
entity
=
$item
->
entity
->
getTranslation
(
$this
->
langcode
);
$
paragraph
=
$paragraph
->
getTranslation
(
$this
->
langcode
);
}
}
else
{
else
{
$
item
->
entity
->
set
(
$langcode_key
,
$this
->
langcode
);
$
paragraph
->
set
(
$langcode_key
,
$this
->
langcode
);
}
}
}
}
}
}
else
{
else
{
// Add translation if missing for the target language.
// Add translation if missing for the target language,
if
(
!
$item
->
entity
->
hasTranslation
(
$this
->
langcode
))
{
// if the paragraph is translatable at all:
if
(
$paragraph
->
isTranslatable
()
&&
!
$paragraph
->
hasTranslation
(
$this
->
langcode
))
{
// Get the selected translation of the paragraph entity.
// Get the selected translation of the paragraph entity.
$entity_langcode
=
$
item
->
entity
->
language
()
->
getId
();
$entity_langcode
=
$
paragraph
->
language
()
->
getId
();
$source_langcode
=
$this
->
sourceLangcode
??
$entity_langcode
;
$source_langcode
=
$this
->
sourceLangcode
??
$entity_langcode
;
// Make sure the source language version is used if available.
// Make sure the source language version is used if available.
// Fetching the translation without this check could lead valid
// Fetching the translation without this check could lead valid
// scenario to have no paragraphs items in the source version of
// scenario to have no paragraphs items in the source version of
// to an exception.
// to an exception.
if
(
$
item
->
entity
->
hasTranslation
(
$source_langcode
))
{
if
(
$
paragraph
->
hasTranslation
(
$source_langcode
))
{
$
entity
=
$item
->
entity
->
getTranslation
(
$source_langcode
);
$
paragraph
=
$paragraph
->
getTranslation
(
$source_langcode
);
}
}
// The paragraphs entity has no content translation source field
// The paragraphs entity has no content translation source field
// if no paragraph entity field is translatable,
// if no paragraph entity field is translatable,
// even if the host is.
// even if the host is.
if
(
$
item
->
entity
->
hasField
(
'content_translation_source'
))
{
if
(
$
paragraph
->
hasField
(
'content_translation_source'
))
{
// Initialise the translation with source language values.
// Initialise the translation with source language values.
$
item
->
entity
->
addTranslation
(
$this
->
langcode
,
$
entity
->
toArray
());
$
paragraph
->
addTranslation
(
$this
->
langcode
,
$
paragraph
->
toArray
());
$translation
=
$
item
->
entity
->
getTranslation
(
$this
->
langcode
);
$translation
=
$
paragraph
->
getTranslation
(
$this
->
langcode
);
$manager
=
\Drupal
::
service
(
'content_translation.manager'
);
$manager
=
\Drupal
::
service
(
'content_translation.manager'
);
$manager
->
getTranslationMetadata
(
$translation
)
$manager
->
getTranslationMetadata
(
$translation
)
->
setSource
(
$
item
->
entity
->
language
()
->
getId
());
->
setSource
(
$
paragraph
->
language
()
->
getId
());
}
}
}
}
// If any paragraphs type is translatable do not switch.
// If any paragraphs type is translatable do not switch.
if
(
$
item
->
entity
->
hasField
(
'content_translation_source'
))
{
if
(
$
paragraph
->
isTranslatable
()
&&
$paragraph
->
hasField
(
'content_translation_source'
))
{
// Switch the paragraph to the translation.
// Switch the paragraph to the translation.
$
item
->
entity
=
$item
->
entity
->
getTranslation
(
$this
->
langcode
);
$
paragraph
=
$paragraph
->
getTranslation
(
$this
->
langcode
);
}
}
}
}
$items
[
$delta
]
->
entity
=
$
item
->
entity
;
$items
[
$delta
]
->
entity
=
$
paragraph
;
}
}
}
}
$this
->
tempstore
->
set
(
$this
->
layoutParagraphsLayout
);
$this
->
tempstore
->
set
(
$this
->
layoutParagraphsLayout
);
...
...
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