Problem/Motivation
Related to #2946333: Allow synced Layout override Translations: translating labels and inline blocks
But this would be for defaults.
Proposed resolution
Remaining tasks
Basic implementation
Define where to set what's the default language of the layout? (like in views)
Check why URL is not accessible (403) in some cases (#64)
Hide "Translate layout" link if translation is disabled
Implement tests
Review
Commit
User interface changes
API changes
Data model changes
Release notes snippet
IMPORTANT:
The MR requires MR!1505 from #2946333: Allow synced Layout override Translations: translating labels and inline blocks! (https://git.drupalcode.org/project/drupal/-/merge_requests/1505#note_59580)
You have to use both combined to make it work!
| Comment | File | Size | Author |
|---|---|---|---|
| #88 | 3044993-88.patch | 32.23 KB | rodrigoaguilera |
| #87 | 3044993-87.patch | 8.28 KB | rodrigoaguilera |
| #85 | 3044993-85.patch | 32.16 KB | l_vandamme |
| #79 | 3044993-79.patch | 32.4 KB | pjonckiere |
| #75 | 3044993-d10-75.patch | 40.51 KB | hitchshock |
Issue fork drupal-3044993
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
tedbowHere is the first in process patch. Patch includes #2946333-153: Allow synced Layout override Translations: translating labels and inline blocks but I also uploaded a do-not-test patch with just the changes for defaults. I had to make 1 change that affects both which I will update #2946333 with after this.
I had very limited experience with config_translation's APIs before so any help/feedback on that would be great
this patch
\Drupal\layout_builder\ConfigTranslation\EntityViewDisplayMapper. This should probably be renamed because it only handles the layout builder settings. This should be able to co-exist with #2546212: Entity view/form mode formatter/widget settings have no translation UI. Right now there is no tab generate so you have to go to the page direclty, /translate from dispaly(as test does)Comment #3
tedbowlayout_builder_config_translation_infoand instead gets from the route because these are dynamicComment #5
tedbowThis is deprecated and not used here.
This will fail in tests where 'field_ui_base_route' is not set for the entity type.
I first tried making sure the base route exists but looking at
config_translation_config_translation_info()it doesn't do this. I wondered why and found #2230091: Route rebuilding is not guaranteed to finish in time for the next request where checking if the route exists actually was removed. So I am following that pattern.Comment #7
tedbow#5 was random failure in a media test.
\Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage::getTranslationOverride()so it loads and therefore saves the correct configurationLayoutEntityDisplayMapperbecause this doesn't affect on all parts of the config entity\Drupal\layout_builder\ConfigTranslation\LayoutEntityDisplayMapper::getEditRoute()so the edit form works nowComment #8
tedbowThe key for set here needs a ".configuration" on the end.
Needs to use 'configuration'
Comment #10
tedbowThis caused the kernel test to fail in #8
\Drupal\layout_builder\ConfigTranslation\LayoutEntityDisplayUpdater::presaveUpdateOverrides()which updates the override component configuration for any components that have moved to a new section. This needs because\Drupal\language\Config\LanguageConfigFactoryOverride::onConfigSavewould filter out any override configuration that doesn't match the new nesting structure of the component under the new section.Also the configuration would not load correctly.
Right now I am doing this in
layout_builder_entity_view_display_presavehook. I first had it inlayout_builder_entity_view_display_updatebut this too late because\Drupal\language\Config\LanguageConfigFactoryOverride::onConfigSavewould have already run.Another option would be too just do an event subscriber that listens for
onConfigSavebut at that point we only have config array and not the config entity. I also don't think we would the original data so it would be harder to just update the components that moved to a new section.This sets the configuration but doesn't check if the component was previously in a different section. I added this.
Comment #12
tedbowThis brings up to #2946333-164: Allow synced Layout override Translations: translating labels and inline blocks #164
There are some other fixes in here which should fix other tests
Comment #16
grayle commentedI rerolled it against 8.9, but I either messed up or I'm not seeing how this patch allows you to translate default layout builder config.
Comment #17
grayle commentedAlright, think something went wrong adding the patch to a running site (ran updb and it didn't fail), but reinstalling from scratch it works fine.
Now to see if I can add a button and the "don't show content preview" option.
Comment #18
grayle commentedOk, translate button added and content preview toggle as well.
Also seems I uploaded a busted version of the patch before, so fixed that too. Changes are in interdiff.
Comment #19
grayle commentedAdded config_translation module check
Comment #20
rajandro commentedWorking on it.
Comment #21
rajandro commentedRerolled most of the functionality of this long patch and adding here. Needs to work on it to make it completely reroll for 9.1.x. However, I think we can break the functionality if possible so that it can be helpful to review and do any changes for this functionality.
Thanks
Rajandro
Comment #22
rajandro commentedComment #23
rajandro commentedComment #24
rajandro commentedFixed the #21 error
Comment #25
rajandro commentedFIxed phpcs violation of #24, adding interdiff from #21 to #25
PS: Four depreciation message needs to address lie as mentioned below:
+ @trigger_error('The entity_type.manager service must be passed to \Drupal\layout_builder\Element\LayoutBuilder::__construct(). It was added in Drupal 8.8.0 and will be required before Drupal 9.0.0.', E_USER_DEPRECATED);+ @trigger_error('The plugin.manager.block service must be passed to \Drupal\layout_builder\InlineBlockEntityOperations::__construct(). It was added in Drupal 8.7.0 and will be required before Drupal 9.0.0.', E_USER_DEPRECATED);Thanks
Comment #26
tedbow@Grayle and @rajandro thanks for the reroll efforts.
re #21
I am sure what you mean. Which patch were you working off for the reroll?
Almost always we don't do a partial reroll unless there a specific, state reason to not include a part of the original patch. With a partial reroll if we want the original functionality we still have to go back to the original patch to figure out what is missing.
It looks like your patch was nearly the same size so maybe you do include all of it?
Comment #27
rajandro commented@Ted, Thank you.
re #26
I have taken "3044993-12_plus_2946333-164-rerolled89x-19.patch" as a reference to reroll.
Thanks
Rajandro
Comment #28
grayle commentedAnd 3044993-12_plus_2946333-164-rerolled89x-19.patch is a full reroll, done using the proposed methods here: https://www.drupal.org/patch/reroll
Only hiccup was setContext method for DefaultsSectionStorage, which was added to core since the #12 patch, but I merged those (can be seen here: https://www.drupal.org/files/issues/2020-06-22/interdiff_16_18.txt). Didn't want to take any chances, so parent:: call is in between the two bits of code to match both sources.
Comment #29
grayle commentedOk, seems there was a duplicate declaration of a property in the tests. Fixed that, again for 8.9.x. Sorry I'm not rerolling against 9.1 dev but we're still a ways off from moving to D9 and we need translations for LB now.
Comment #30
grayle commentedReroll based on patch 202 in the other issue and this issue's 12 patch.
Comment #32
dravenkComment #33
anmolgoyal74 commentedComment #34
anmolgoyal74 commentedRe-rolled #30.
Comment #35
heddnHopefully fixes up some PHPCS and test failures
Comment #36
heddnThis could really use someone figuring out what parts of this patch are duplicated in #2946333: Allow synced Layout override Translations: translating labels and inline blocks and creating a 2nd patch that builds upon that work. The last time we had that split-up was back in #12. But I can't tell what since then is new or just attempts at fixing things up in a re-roll.
Leaving the re-roll tag on here, but only because we need to figure out what has changed in this issue since #12 and build a (hopefully) smaller patch that builds on top of the other.
Comment #37
heddnNW for a re-roll.
Comment #38
vsujeetkumar commented@heddn I have checked after #12 there are no magor changes as per my understanding, few rerolls and PHPCS fixes are there, I am trying to understand, but no clue found, can you please help me out in this how to reroll this.
Comment #39
NitinLama commented@here removing unused use statement.
Comment #40
NitinLama commentedComment #41
vsujeetkumar commentedFixing CSPell issue.
Comment #43
anmolgoyal74 commentedFixed failing test cases.
Comment #45
grayle commentedHere's #12 rerolled on top of the latest patch in the override issue, but not combined, so as a separate patch you can apply after applying the other issue's patch.
And then there's #12 + some minor updates in the same formfactor.
Hope this helps clear things up.
Comment #46
grayle commentedComment #47
grayle commentedForgot some pluses, added test changes from last rerolled patch.
Comment #48
grayle commentedComment #49
DonAtt commentedTesting with Drupal 9.1.4. Installed both override issue #224 and this issue #48.
Generally works good, I could translate labels and they display correctly.
However, the "Translate layout" link URL is not always good.
First issue:
My installation uses a subdirectory in the path: http://localhost:8080/web/en/admin/bat/type-bundle/venue/edit/display/teaser
The prefix is duplicated: http://localhost:8080/web/web/en/admin/bat/type-bundle/venue/edit/display/teaser/translate
Second issue:
The default layout URL doesn't contain "/default" at the end: http://localhost:8080/web/en/admin/bat/type-bundle/venue/edit/display
So the translation link also misses that route param: http://localhost:8080/web/web/en/admin/bat/type-bundle/venue/edit/displa...
Should be: http://localhost:8080/web/en/admin/bat/type-bundle/venue/edit/display/default/translate
The problem is here, using the current URL as a base is not reliable:
I've attached a quick fix patch that solves the problem for me, can be useful for someone else as well.
(Maybe it can give an idea for a permanent fix - but it's not intended to be the permanent solution itself.)
Comment #51
thomasdbcklr commentedTested with Drupal 9.2.5. Installed both override issue #238 and this issue #48.
Getting a 404 'page not found' when trying to translate a layout while the url looks fine: '/admin/structure/types/manage/[bundle]/display/[viewmode]/translate'
#49 Did not apply for me
Comment #52
nginex commentedI found another bug which is caused by #48.
The issue is:
I expect that for multilingual site when we clear cache in CLI, it should clear everything including field definitions cache BUT the patch from #48 adds layout_builder_config_translation_info() which is triggered after cache clear and it recreates cache of field definitions from scratch and might use different config override language than current language. If there is mismatch there will be a moment when you can see field labels in one language while your interface language is another language.
Here is improved patch which fixes the described above issue.
Comment #53
kostyashupenkoComment #55
anybodyUpdating the priority to Major as of the priority of the META issue. It would be expected to be able to translate all elements provided by core, but that's still not the case here. For default layouts, the labels and inline blocks still can't be translated.
Confirming this still needs work, the button "Translate layout" links to a non-existing page:
- /admin/structure/types/manage/aircraft/display/default/translate = 404 (Page not found)
- /admin/structure/types/manage/aircraft/display/translate = 403 (Access denied - with admin!)
The layout was created prior to applying the patch.
Comment #56
anybodyCreated an issue fork from #52 (1:1) to proceed there. We should really get this fixed for 9.4, the current situation isn't appropriate for multilanguage sites with layout builder.
Comment #57
matthijsThe patch from #52 has an issue when using domain-based language selection, an exception is thrown because Url::fromUserInput() gets an absolute URL. The attached patch fixes this.
Comment #58
anybodyPlayed around with the patch from #49 but wasn't successful, so reverting the MR to the previous state. My key problem is that I don't even understand which path / route is expected here. The current and the proposed solution both seem dirty?
What's the expected path for display layout translation? I can't get any working.
Comment #59
anybody@Matthijs could you please provide an interdiff or fix it in the MR?
Comment #61
matthijs@Anybody: done!
Comment #62
anybodyMR is missing the newly added files from the patch. I'll fix this asap, seems I forgot the git add -.-
Comment #63
anybodyIMPORTANT:
The MR requires MR!1505 from #2946333: Allow synced Layout override Translations: translating labels and inline blocks! (https://git.drupalcode.org/project/drupal/-/merge_requests/1505#note_59580)
You have to use both combined to make it work!
Comment #64
anybodyMR should be fine so far, but I still get "Access denied" in the generated path:
admin/structure/types/manage/{NODE-TYPE}/display/translate
with user 1 (admin)
Any ideas?
This happens despite whatever I configure for translation settings on the node type. Even if translation is enabled, disabled, language set to a specific language, etc.
Comment #65
matthijsSome changes were missing in my previous patch (seems i forgot to "git add" as well), here the new one.
Comment #66
matthijsFixed missing use statement.
Comment #67
anybody@Matthijs: FYI you can always very simply create a patch file from Merge Request URL + ".diff" or click the "plain diff" link above:
https://git.drupalcode.org/project/drupal/-/merge_requests/1921.diff
So you don't have to create the patch file yourself with such risks.
Comment #68
anybodyComment #72
nginex commentedHere is an improved d10 version of the patch based on #66 patch.
Tried to create an interdiff but it failed. Also if we use MR approach we need to switch the target branch for the fork and rebase it.
Comment #73
nginex commentedComment #74
smustgrave commentedFor the CC failure.
But can the IS be completed also, with the proposed solution
And if this requires #2946333: Allow synced Layout override Translations: translating labels and inline blocks then this should be postponed till that lands.
Comment #75
hitchshockThe last patch isn't compatible with the event dispatcher. The first argument must be an event object.
Updated a patch a bit.
Comment #76
hitchshockAlso, the code
if ($section_storage->getTranslatedComponentConfiguration($component->getUuid())) {in LayoutEntityDisplayMapper::hasTranslatable() breaks the 'Translate layout' feature on the content view mode.How to reproduce it:
- enable config_translation module
- enable layout builder for content type
- configure Layout Builder for some view mode
- try to make a translation of the layout
I see two issues here:
- The ConfigTranslationOverviewAccess::doCheckAccess() uses hasTranslatable() function and in this case $section_storage doesn't have language context
- even I'll add the language context the result still will be wrong, cuz getTranslatedComponentConfiguration() expects that config already contains the translation, it means that it doesn't work for 'add' translation action
Comment #77
circuscowboy commentedI am trying to solve the layout builder translation issues for the first time and I am running into difficulties.
If I use patch 75 on its own I get the following error message:
Error: Interface "Drupal\layout_builder\TranslatableSectionStorageInterface" not found in /var/www/pwnhc/web/core/modules/layout_builder/src/DefaultsSectionStorageInterface.php on line 12 #0 /var/www/pwnhc/vendor/composer/ClassLoader.php(571): include()If I apply the patch in this issue, https://www.drupal.org/project/drupal/issues/2946333 based off this merge request https://git.drupalcode.org/project/drupal/-/merge_requests/5956#note_259636 then that error goes away and I get a button called "Translate Layout".
The old merge request listed above (https://git.drupalcode.org/project/drupal/-/merge_requests/1504#note_194458) no longer applies to 10.2 - If this new patch would have fully worked I would replace it in the description.
I am having 2 issues with the 2 patches. Firstly I am using a path based URL and the path is duplicated in the Translate Layout button link so it goes to a page not found.
Details
Secondly with the corrected link I gotten 2 different outputs
If anyone can guide me to get better results I would appreciate it.
Comment #78
sboden commentedAs documented in https://www.drupal.org/project/drupal/issues/3420019 patch #72 correctly applies to a Drupal 10.2.2 instance, but it breaks the site.
Comment #79
pjonckiere commentedRerolled for D10.3
Comment #80
pjonckiere commentedComment #81
liquidcms commentedSorry, lost in where this is at. I swear (back in D9 at some point) i had tabs when in LB and one of those was to "Translate layout"; but now (D10.2.2.) NO tabs.
I have a vanilla D10.2.2 site with these patches:
- https://www.drupal.org/files/issues/2024-06-28/3044993-79.patch
- https://www.drupal.org/files/issues/2024-03-15/2946333-327_Revised_patch...
Additionally:
- Article type set to be translatable
- Basic block set to be translatable
- Article default view mode set to use LB (for all nodes)
- Add inline basic block using LB
There is no apparent UI to access translation of this. I have tried a couple urls as mentioned above:
en/admin/structure/types/manage/article/display/translate - access denied
en/admin/structure/types/manage/article/display/default/translate - throws:
Error: Call to undefined method Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage::getTranslatedComponentConfiguration() in Drupal\layout_builder\ConfigTranslation\LayoutEntityDisplayMapper->hasTranslatable() (line 55 of E:\www\SSC\d10.0\web\core\modules\layout_builder\src\ConfigTranslation\LayoutEntityDisplayMapper.php).Any hints?
Comment #82
liquidcms commentedswitched to patch from #75 and now i see a Translate Layout button (at least now i know what the expected ui is); but it throws this error:
Error: Call to a member function get() on null in Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage->getTranslatedComponentConfiguration() (line 481 of E:\www\SSC\d10.0\web\core\modules\layout_builder\src\Plugin\SectionStorage\DefaultsSectionStorage.php).Comment #83
liquidcms commentedand now, magically, button gives Access Denied at: en/admin/structure/types/manage/article/display/translate
Comment #84
l_vandamme commentedRerolled patch for 11.x (using my rebase commit of https://www.drupal.org/project/drupal/issues/2946333 MR 5956)
Comment #85
l_vandamme commentedWoops, missed an import in my patch
Comment #86
mahde@l_vandamme The last patch doesn't apply to the latest Drupal 11.
Comment #87
rodrigoaguileraReroll attached of #85 applied agains Drupal 11.2.2 (with #356 from here also applied)
Comment #88
rodrigoaguilera#87 is an incomplete patch, here is the right version