The Book module does not fully use the new translation features we have. It doesn't translate the node titles in the different menus it generates.
Steps to reproduce:
- Configure Book content type for translation
- Enable a second language
- Create a book outline in English
- Translate each node in the outline
- Navigate the book in the second language
The nodes get loaded correctly, in the correct language. However, the navigation in the node footer, as well as the Book block, display the node titles in English, which is incorrect.
I'm the maintainer of the Book Translation module. D8 will make much of the module obsolete (which is great). However, it misses this small part.
Release note snippet
Book navigation now displays translated titles 🎉
Comments
Comment #1
wadmiraal commentedHaving a look at it.
Comment #2
wadmiraal commentedOther stuff to do for now, might get back to it later.
Comment #3
kattekrab commentedHey @wadmiraal - are you likely to have time to circle back to this one?
Strike me it's a good idea if it's not too much work!
Comment #4
astra commentedWhich version of Drupal 8 can make Book navigation translatable?
Thank you!
Comment #5
Matroschker commentedI checked this again with Drupal 8.0.1 and it does not work.
It would be very good if this could handle in standard.
Thank you.
Comment #6
wadmiraal commentedDoesn't work with Drupal 8.0.2 either. It has actually been disabled in
book.module:That 2nd parameter passed to
loadBookLinks()(FALSE) is the$translateparameter, as seen here (src/BookManager.php):There are 2 things I don't understand from this code:
1. Why is
$translatebeing passed toBookOutlineStorage::loadMultiple()? TheloadMultiple()method's 2nd parameter is the$accessparameter, and controls wehther anode_accesstag should be added to the query. Shouldn't this always be the case? How are we checking node access in the context of the book navigation then? And why does this depend on the outline being translated or not?2. Why was the translation specifically disabled?
Does the 2nd question have anything to do with this: when I change the code to this (meaning, I'm disabling access checks, but enabling translations):
Apache dies with a Segmentation fault (
AH00052: child pid 238 exit signal Segmentation fault (11)). Any thoughts on what could cause this? Is this the reason this was temporarily disabled?Comment #9
erikwegner commentedHere is a patch that addresses the list of child pages and the bread crumb titles.
Comment #10
erikwegner commentedHere is a patch that addresses the list of child pages and the bread crumb titles.
Now the links point to the correct language.
Comment #11
kholloway commentedI have have confirmed that this patch works for me. Unsure if testing is needed before this can be applied.
Just to be specific this fixes the breadcrumb, Book Navigation block as well as the (lower) link menu "next" and "previous" links.
Comment #12
roald commented#10 appears to work fine for me as well
Comment #13
dawehnerThe code looks reasonable, I'd say, but we really need test coverage to be able to sure it will be working in the future.
Comment #15
Leagnus commented#10 works fine. Thank you, ErikWegner.
Comment #16
noximuz commented#10, links are translated, but still point to a different language pages (in book tree section).
Comment #17
erikwegner commentedPatch including tests for:
Comment #18
erikwegner commentedComment #19
erikwegner commentedCode for test reformatted
Comment #21
erikwegner commentedReformatted the code
Comment #24
erikwegner commentedComment #25
dawehnerNice test coverage!
I'd just have named it BookTranslationTest, one less abbreviation people would have to know :)
Comment #26
erikwegner commentedThat's a good point. Here is the patch with the class renamed.
Comment #27
erikwegner commentedComment #28
swentel commentedSo the patch seems to be doing it's job fine.
On thing though which is important: it's entirely possible a node is not translated in a certain language, so should we then ignore this in the tree when we're showing the navigation in a different language. It's a requirement for the site I'm working on right now to hide it, so maybe this could be a setting on the block and use that as a default?
To visualize the problem. In english (default language) we have this tree
- installation (node 1)
- mac (node 2)
- linux (node 3)
- windows (node 4).
But in dutch, only the installation node is translated, the rest is not. Yet in the navigation tree in the dutch, we see the 3 children which don't make sense to be displayed there.
This behavior (a bug imho) can also be seen in the traversal links at the bottom.
Note, I'd personally consider this as a bug report (maybe even major), as multillingual book navigations are basically useless right now.
Comment #29
pritishkumar commentedImproved intendation.
But I don't know why, I am not able to create interdiff files
Comment #30
dunebl#53 is doing the job... many thanks for this!!!!
Note that in "Detection and selection" page, if I check "User" to have the settings like the screencapture, the block is not translated even if I click on another language on the language switcher block...
Comment #32
sakhan commentedSee #35.
Comment #33
sakhan commentedComment #34
sakhan commentedComment #35
sakhan commented#26 (and #29 which is same as #26 but with improved indentation) work fine for me but I noticed that one issue is still there.
Along with the issues which are reported, there is an another issue which you can reproduce like this:
You will notice that the titles are saved for the English language not for the second language, which is incorrect.
Before #26 patch the Title fields in /admin/structure/book "Edit order and titles" were always loaded with the English translation.
After #26 patch, when visiting the "Edit order and titles" page, the Title fields now get loaded correctly but if you edit the Title fields and save them, the titles are saved for the default-language/English not the currently selected second language (just like without the patch). For solving this issue here is the updated patch which is same as #26 (#29 too) with additional work which addresses the above issue.
Comment #36
sakhan commentedThe names/titles of the books are not correctly translated in /admin/structure/book. They are set to English/default-language in all cases.
Steps to reproduce:
You will notice that although you have selected the second language, the book titles are displayed in English.
This patch addresses to resolves this issue too. After applying this patch you will see that the book titles are displayed in the correct translation.
Comment #37
erikwegner commented@sakhan: I am interested in a use case where the structure of a book is different for several languages. Could you please describe one and explain the benefits? Maybe it could be an option for each book to choose whether the structure is the same for all languages?
Comment #38
dani3lr0se commentedI've tested via simplytest.me and followed the steps to reproduce that are in #36. However, it doesn't appear to be working. I'm still seeing the book titles displayed in English. I'm pretty sure I've followed the steps correctly, but perhaps someone else could make it work.
Comment #39
sakhan commented@Daniel_Rose Most probably your Interface text language detection settings are not properly configured. Please visit admin/config/regional/language/detection and choose a suitable detection method and then try again. I have tested on my end that if I don't set an interface language detection method then the books titles are shown in the default language.
Comment #40
dani3lr0se commented@sakhan, no problem. I'll give it another try. Thanks for the feedback. :)
Comment #41
sakhan commented@Daniel_Rose Please login to https://dubbr.ply.st/ as admin/admin and then visit https://dubbr.ply.st/admin/structure/book AND https://dubbr.ply.st/ur/admin/structure/book, hopefully you will notice the difference. The other language used is Urdu(ur).
Comment #42
dani3lr0se commented@sakhan, I definitely notice there. I guess I didn't correctly setup the language translation. My apologies and thank you very much for your feedback and help. :)
Shall we mark this as RTBC since it's working?
Comment #43
duneblHello,
I got few notices when applying #36
Comment #45
nesimo commentedPatch for Drupal 8.4.x working here too. Thanks a lot.
Comment #46
erikwegner commentedComment #47
avpadernoThe
Drupal\book\BookBreadcrumbBuilderclass implements a service, so using\Drupal::languageManager()in its methods is wrong.Comment #48
erikwegner commentedUsing service for language manager. Adding translation to html export.
Comment #49
avpadernoAs class property, the code should use
$this->languageManager, not$this->language_manager, in the same way it's used$this->viewBuilder.Comment #51
erikwegner commentedPatch: Test fix, code style
Comment #53
erikwegner commentedTypo in test
Comment #54
avpadernoThere is just something more that I think needs be changed.
It's not clear what that HERE means. If it is referring to the previous comment, then I would rather move that comment.
Note- is not using the correct punctuation. I would just leave that out, since every code comment is a note about the code.
It seems the comment is explaining why the code doesn't verify the users have permission to access the node. In that case, I would rather change the code like this.
Should not the code verify the users have access to the translation node? The existing code (i.e. the code before the patch) is not getting the translated nodes, so it is also not checking the users have access to the translation nodes.
Probably that comment should be removed, and the code verify the users have access to the translation node.
Comment #55
avpadernoI was also checking if the following code could be simplified, since it is used more than once.
The only simplification I could get is the following one, which replaces two
if()statements with one.$node->isTranslatable()is necessary because it checks there is more than a language added to the site, and we don't want to show a translation that was added when the site had two or more languages, after the site is back to having a single language.Comment #56
erikwegner commentedThat
// HEREwas an old marker where to insert the new code. Just forgot to remove that.For those
if-conditions: I prefer to have them as separate statements for legibility and creating diffs.Btw: is it possible to have access to a node in one language but not in the other?
Comment #57
avpadernoSince the translation is a different node, users could have access to a node, but not the other one, even if the latter is the translation of the previous.
Comment #58
erikwegner commentedTranslation is not a different node in most cases, each language is a set of field values (doc). The published status is also shared across all languages.
Comment #59
avpadernoThey are two different node objects with the same ID, but different properties (e.g. author, creation date, active language). As such, a module implementing a content access hook could deny access to the translation. In fact, there are core tests verifying that.
Comment #60
avpadernoSee
NodeAccessLanguageTest::testNodeAccess().The code acting behind the scene is in
node_access_test_node_access().Comment #61
erikwegner commentedThank you for the example, that shows what can be possible.
From my point of view, the patch we have developed so far makes at least these three assumptions:
From my end user perspective, the issues with untranslated links and nodes can be solved easily by applying this patch. But if any of the above points is not valid, then it needs a broader approach to the problem. I am thinking of the book module's storage structure and all internals, there are many places that might need a new concept.
Perhaps it is also possible to fix this issue with the given patch and address any further concerns in a new issue that is handled by a more skilled person?
Comment #62
avpadernoUsing the default language, and without this patch, the Book module gives me the links only for the nodes to which I have access. If I cannot access a book page, I don't see the link to that page.
This patch introduces a difference in the behavior of the module. It could be classified as bug, since it gives me a link to a node to which I could not have access.
As side note, also the published status is translatable, which means a translation could be published, and another translation not.
Comment #63
danghoaiphuc commentedHi,
I am not a techie guy so May I ask for your advice if I can use the patch #56 as stated for Drupal 8.6 for my Drupal 8.5? Or, should use the patch #47? Thanks a lot.
Comment #64
leventdal commentedInstalling 56 on 8.5.2 gave me white screen error. "encountered error"
Currently this issue makes book navigation useless in multilingual sites. It displays only original content. And there are problems with breadcrumbs.
Here is the error I receive.
drupal __construct() must implement interface Drupal\Core\Language\LanguageManagerInterface, none given, called in /home/xxxxxx/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php on line 266 in Drupal\book\BookBreadcrumbBuilder->__construct() (line 52 of core/modules/book/src/BookBreadcrumbBuilder.php).
Comment #65
erikwegner commentedAfter applying #56, you have to flush the caches (e.g.
drush cr).Comment #66
krug commented#56 drupal 8.5.2
English and custom language.
Thanks @erikwegner
Comment #67
leventdal commentedClearing the cache didn't work in 8.5.2. I've hidden the book navigation by css. Unfortunately that was the only viable option.
Comment #68
erikwegner commented@leventdal
How did you clear the caches?
Do you get another error message now?
Comment #69
leventdal commented@ErikWegner
I cleared cache from the performance page.
I didn't try it again with 8.5.3
Comment #70
dawehnerPotentially other users have subclasses this class. Given that I think you should make the constructor argument optional aka.
$this->languageManager = $language_manager ?: \Drupal::service('language_manager')Note: This would have prevented the problem described by #64
Comment #71
erikwegner commented@dawehner Are you sure that a subclass is causing the exception? But that is actually a valid concern: how do/should subclasses handle dependencies (especially changes of constructor arguments) of their parent classes?
Comment #72
avpadernoComment #73
anibal commentedPatch #56 works perfectly for me in drupal 8.6 dev in the following link site as example.
http://www.ergophthalmology.com
Comment #75
mpolishchuck commentedHello.
Patch #56 works, but I caught one more problem. When we're trying to edit book outline (change book item parent for example) - the options in "Parent item" are not translated and is being displayed in base language. I've done some investigation and solved that (more or less). Also added a test for this. Maybe it will be helpful for someone.
Comment #76
unknownmrb commented#75 works perfectly, thank you!
Comment #77
godwing commentedI have entered the code #75 manually and have got the white screen with the message (cache was cleared before it):
"The website encountered an unexpected error. Please try again later.
Recoverable fatal error: Argument 3 passed to Drupal\book\BookBreadcrumbBuilder::__construct() must implement interface Drupal\Core\Language\LanguageManagerInterface, none given, called in /home/useraccount/mysite.org/core/lib/Drupal/Component/DependencyInjection/Container.php on line 266 and defined in Drupal\book\BookBreadcrumbBuilder->__construct() (line 52 of core/modules/book/src/BookBreadcrumbBuilder.php)."
My site version is drupal 8.6.4
Server hoster: PHP Version 5.6.35
-------------------------
Could you suggest any solution, please? (I am an ordinary user using ready-made solutions.)
Comment #78
erikwegner commentedPlease try to clear the cache after applying the patch.
Comment #79
godwing commented@ErikWegner
Unfortunately, I had no chance to do it. Any menu navigation led to this message.
Comment #80
erikwegner commentedI try to change the code, so that it works without clearing the cache.
Comment #81
godwing commented@ErikWegner
Thanks for your support. I once again entered all the code manually. This time I previously opened the Clear Cache page. After entering the code and running the cache, I got a white screen without any messages. When I manually moved to the root of the site, everything works well, and the translation of the book is displayed correctly.
But whenever I hit ../development/performance/Clear cache I get a white screen without messages again.
Status Report informs that there are no errors. If I Run Cron - everything is OK. Recent log messages page - no any messages after Clear Cache. I optimized the database, cleared the browser's cookies, went out and went back to my site, but after Clear Cache I always get a white screen without messages.
Additionally, I inform you that initially I had settings ... Configuration> Regional and language> Russian as default. Then I decided to put finally the English as Default. After that, I entered code #75.
Perhaps an error due to the pre-change of the default language of the site?
Comment #82
erikwegner commentedIf dependency injection does not know about additional required service, retrieve service from global object. This should handle the case when clearing the cache is not possible and avoid a WSOD.
Comment #83
godwing commented@ErikWegner
Hello, Erik. Unfortunately, the new changes did not fix the WSOD error. When I restored the original files of the directory Book, the cache cleaning worked correctly.
Comment #84
andrii_svirin commented#82 applied patch for drupal 8.6.4 - working.
Comment #85
embeau commentedI also applied patch #82, which appears to be working. Hoping this functionality can be committed to core asap.
However, one thing it does is that if I am on a French page, the book outline block still displays any English pages in the outline that were not translated. I believe this is intentional, but for what I need, it should only list the pages in the outline that are of the same language as the current page. Same with the next/previous pages at the bottom of the page.
Comment #86
andy_w commentedNot sure if this is relevant; but in the event you want to see both unpublished pages and have them show translated then this patch could be applied after the patch in [26552] - which I would assume / hope will be rolled in at some point.
Comment #87
godwing commented@ErikWegner
Haveing a new Drupal update the patch #82 is working without any problem. Thank you.
Comment #89
dunebl#86 and #82 doesn't apply on 8.7
Comment #90
godwing commentedPatch #86 at Drupal 8.6.13 produces error, when I try to open a translated book: "The website encountered an unexpected error. Please try again later."
Patch #82 is OK.
Comment #91
kostyashupenkoreroll of #86 patch
Comment #93
avpadernoThere is an exception raised in a test.
Comment #94
brtamas commentedComment #95
brtamas commentedComment #96
dbielke1986 commentedPatch #75 is working like charme for Drupal 8.7.x if you change the "EntityManagerInterface $entityManager" to "EntityTypeManagerInterface $entity_type_manager"
The other patches are fixing the export issue, but not the book navigation issue.
Comment #97
godwing commented@JD_1
I tried your solution for Drupal 8.7.3, it doesn't work, any option. [The website encountered an unexpected error. Please try again later.]
So, finally, do we have any working patch?
Comment #98
dbielke1986 commented@godwing
I will send you my modified files tomorror, if you like.
This is working perfectly fine on our 8.7.3 installation.
Comment #99
dbielke1986 commentedAttached you will find modified files for drupal 8.7.3, based on Patch 75
Comment #100
godwing commented@JD_1
Thank you, Daniel! It began to work, really, like a miracle. I replaced the files with yours. In my inexperienced view there are no errors, but you can look at the published book.
Comment #101
suchdavid commented@JD_1 Thank you for the files, I created a patch from them for 8.7.3.
Comment #102
mauriciomedeiros commentedDoes this fixes the translation of the book tree as well? The one which shows below the content on bartik theme at least?
Comment #103
dbielke1986 commentedYes
Comment #104
mauriciomedeiros commented@JD_1 and everyone involved, you are my heroes, thanks to all of you.
The patch works like a charm as far as I could test in the past few minutes.
This needs to be included in the next core update :D
KR
Mauricio
Comment #105
andrii_svirin commented#101 Working for 8.7.3 for me. Thanks.
Comment #106
godwing commented@mauriciomedeiros
I agree, it's time to include it into the next core update.
Comment #107
pjudge commented#101 working beautifully on 8.7.4 for me.
Comment #108
mauriciomedeiros commentedWhat is the process for this to be included in the core? Can the community push for it in any way? :D
Apparently it is still not there...
Also, has anyone tested #101 on 8.7.5?
KR
Mauricio Medeiros
Comment #109
avpaderno@mauriciomedeiros It will be included if somebody provides a correct patch. So far, the last patches failed, or failed to apply.
Comment #111
sakhan commentedI am so much frustrated to see that still I can't work on my some projects just because they require book module :(
I am afraid that even if I use some recent working patch that may fail in the next release of the Drupal 8. Why Drupal core maintainers don't take their action to solve this problem once for all as they may know more about how to solve this issue.
Comment #112
sakhan commentedI am waiting for the working multilingual book module for 2 years as you might have noticed from my #35 and #36 patches. With my heavy heart I can say Drupal is losing my interest and loyalty day by day.
On the top of the drupal.org page, the first menu entry says "Why Drupal?" it should be "Why NOT Drupal?"!
Comment #113
levmyshkin#101 Working for 8.7.10 for me. Thanks.
Comment #114
levmyshkin#101 patch helps to display right language version. But it shows page from another language even if page is not translated yet:

Comment #115
levmyshkinComment #116
nicrodgersNeeds re-rolling for 8.8
Comment #117
nicrodgersComment #118
nicrodgersRe-rolled #101 for 8.8.x
Comment #119
avpadernoComment #121
avpadernoThe tests fails because of the following error.
It is repeated for each data set the test is using.
(The other error is test runner returned a non-zero error code.)
Comment #122
nicrodgersComment #123
nicrodgersFix for the failing tests.
Still needs work though as we need a change record.
Comment #124
valthebaldHaven't checked the patch itself, but here are some code style comments:
there should be newline in the end of file
No newline
No newline
Comment #125
Madhura BK commentedComment #126
Madhura BK commentedHave implemented the changes suggested in #124
Comment #127
avpadernoNow the newlines are two. I would suggest to read what https://www.drupal.org/pift-ci-job/1506753 says about coding standards by clicking on 7 coding standards messages.
Comment #128
avpadernoComment #129
Madhura BK commentedComment #130
avpaderno(This is the right patch.)
Comment #131
nicrodgersStill two remaining coding standards issues to fix:
https://www.drupal.org/pift-ci-job/1506832
And needs a change record.
Please can you remember to include an interdiff when uploading new patches, so it's easier to review the changes between versions. Thanks!
Comment #132
Madhura BK commentedFixing the 2 coding standard issues mentioned in #131
Comment #133
Madhura BK commentedComment #134
avpadernoAlso, since the services are getting a new dependency, the class constructors should use code similar to the one used from
CssCollectionOptimizer::__construct().Comment #135
avpadernoAs reference, this is the issue adding that code: #2244513: Move the unmanaged file APIs to the file_system service (file.inc).
Comment #136
vidorado commentedRerolled patch from #132 for Drupal 8.7.x
Comment #137
sakhan commentedAny solid solution so far?
Comment #138
ghost of drupal pastI tried to apply this to latest stable (8.8.3) and had two rejections, rerolled. This is because of the change from entity manager to entity type manager.
Comment #139
swatichouhan012 commentedMoving this to Needs Review.
Comment #140
avpadernoThere isn't yet any BC code as described in comment #134.
Comment #141
sakhan commented@kiamlaluno Can you please discuss in detail what else is needed to solve this issue? I see many of us are just struggling to solve this issue but lacking some expertise so is it possible from your side to contribute to solve this issue once for all please?
One other way I can think of is to give monetary support to the issue resolver to expedite the process.
Comment #142
avpadernoSee comment #134. I quoted the code of the constructor of a class implementing a service for which the parameters have been changed. The constructor has a new parameter with a
NULLdefault value, and it triggers aE_USER_DEPRECATEDerror when the default value is used for that parameter.Similar code needs to be used for any service which get a parameter that it didn't get in older versions.
Comment #143
sakhan commentedDrupal 9 will be released soon but yet the book module lack very basic multilingual support :(
Comment #144
swatichouhan012 commentedpatch #138 failed to apply so i rerolled patch.
@kiamlaluno wrt point in comment #143. can you please provide link for language_manager service where it deprecated ?
Comment #145
avpaderno@swatichouhan012 The language_manager service isn't deprecated.
Comment #142 is saying what code needs to be added when new arguments are added to a service, such as in the case of the language_manager service which is added to the book.manager service.
Comment #146
dbielke1986 commentedThe patch from comment #144 does not work properly. Although the menu title is displayed correctly, the link to the pages is not correct if you use a prefix (like /de or /en in the URL)
Patch 2470896_138.patch is working for me.
Comment #147
levmyshkin#144 and #138 are working fine for me with Drupal 8.9.x-dev.
Comment #149
sakhan commentedDrupal 9 is about to be released soon but still book module is not translatable. So many developers couldn't transform their ideas into realities due to this missing translation feature.
Comment #150
aleevasRe-rolled up to 9.1
Added notice from #142 and new 'Change records'
Comment #151
sakhan commentedPatch from comment #150 working for me with drupal 9.
Comment #152
avpadernoThe deprecation messages need to be updated: If the code is changed in Drupal 9.1.x, the messages cannot say Drupal 8.9.
Comment #153
aleevas@kiamlaluno thank you for review.
You warning make sense, so I changed it to 9.1
Comment #154
avpadernoIt's seems good to go, to me.
Comment #155
sakhan commentedFinally we have a patch that at least works with the upcoming version of Drupal that's Drupal 9! I tested it very extensively and it doesn't fail for me.
Comment #156
jiong_ye commented#144 works for me except that it doesn't render translation's URL but origin's URL.
Comment #157
dbielke1986 commented#156 is working perfectly! Thank you so much
Comment #158
alexpottThis can be if ($parent->isTranslatable() && $parent_book->hasTranslatatioon($langcde)_ {
This looks duplicated I think only one of these code hunks is necessary.
This change is out-of-scope - and I think incorrect.
Comment #159
avpadernoComment #160
avpadernoIt also needs re-roll, since the patch failed to apply.
Comment #161
mrinalini9 commentedComment #162
mrinalini9 commentedRerolled patch for 9.1.x. Still need to address #158 and #159.
Comment #163
cburschkaAddressing 1-2 of #158; 4 is already fixed.
Still needs tests.
Comment #164
avpaderno(Patches aren't testing, if the status isn't changed to Needs review.)
Comment #165
jofitzNo longer requires Reroll.
Setting status back to Needs Work for someone to address #158.3 - still needs tests.
Comment #166
dbielke1986 commented#163 is working fine and has not the mentioned #158.3 issue.
Comment #167
ghost of drupal pastAdded a kernel test. There's no interdiff: BookMultilingualTest is new, that's all. getAllBooks(), bookTreeAllData() and getTableOfContents() are covered.
Comment #168
ghost of drupal pastD'oh I always forget that @group because I run only the single file with phpunit. While at it, I have added asserts to make sure the test actually hits the code paths we want it to hit and another to make sure the current language switcher works. It's possible we want to move the current language switcher to a trait in a separate patch, it looks like it could be very useful for other such tests as well.
Comment #169
penyaskitoRemoving Needs test issue tag, this has good coverage now.
Seems like the request of the deprecation message for the new arguments in constructors are not taken care of yet (see #142).
Happy to RTBC afterwards as looks like this has been tested several times by several people and the latest patch is adding tests but not changing functional code.
Comment #170
ghost of drupal pastI have the messages added and also more tests added but please hold for now: I am having a chat with various maintainers whether the translation to the interface language is correct or not. I feel it's not and it should use content language and the
EntityRepository::getTranslationFromContextmethod should be used. Please wait a few days while we sort this out. If I am not back in a week feel free to continue without me... but I will be.Comment #171
ghost of drupal pastThere's no interdiff here because it'd be bigger than the patch as almost every line touched by the patch has been changed.
Comment #172
berdirthis only works if you add = NULL to the argument, as the type otherwise doesn't allow NULL as a valid value.
I'd recommend to store the language manager, not the current language. that can in theory change during the request.
Interesting. Is there any chance the interface language _also_ affects what we cache here? I suppose not as we can expect all links to be nodes and that's all we translate?
ha, interesting case of "I wish to make the API work as I'd like it to by writing a comment saying it is so" :)
accidentally commented out?
I'm not a huge fan of data providers in anything but unit tests FWIW. This will do the setup() twice for each combination.
Comment #173
ghost of drupal pastBookManager::$booksstores translated nodes and it's not possible to reset it. I suppose we could reset the entire service but based on our chat this is cleaner.Comment #174
avpadernoComment #175
berdirthe data provider is still commented out with a #, I suppose that caused an error otherwise.
Comment #176
ghost of drupal pastAlright, one more then.
Comment #177
berdirHopefully the last review.
another #, but it seems to run and work anyway? we should remove that though.
several parts of the test seem to be basically testing/asserting itself, also the negotiation below. a bit unusual I suppose but doesn't hurt.
type missing here.
also type missing on $langcode @param.
I know it's long, but we should use $language_manager and not $lm per our coding standards
Comment #178
ghost of drupal pastFixed as requested.
Comment #179
berdirthe search & replace added an extra space in several places here.
Feeling bad to set back to needs work because of that, so fixing that and RTBC'ing anyway, I think that's fine as it's just spaces and an extra comma that phpstorm phpcs also complained about.
Comment #180
larowlanThanks for this, a couple of observations / questions - setting to needs review for feedback
ubernit: we can use inheritdoc here
we can and should typehint this as string for new code in my opinion
should we be more explicit here and assert the expected parent crumbs too? e.g. we're just asserting that one of the crumbs matches the child item (#2) but shouldn't we be also testing that the book parent appears in the correct language?
I.e. rather than looping over all links to find one, assert that we have a matching set of titles in the correct language for all of the items?
Comment #181
larowlanWe're also missing deprecation tests here to assert the expected deprecations are raised if the constructor args are missing
Comment #182
pritishkumar commentedAddressing pointers 180.1 and 180.2
Comment #183
berdir> We're also missing deprecation tests here to assert the expected deprecations are raised if the constructor args are missing
We usually don't add tests for that unless there is special complexity, I think it's fine to skip that.
Comment #184
quietone commentedThe patch in #182 does fix the the points, #180.1 and .2.
However, 180.3 still needs to be addressed. Setting to NW.
Comment #185
mindbet commentedThis patch addresses 180.3
In the file
Kernel/BookMultilingualTest.php,
the test sets up two books for testing.
I revised the setUp function so that two books are each nine pages deep.
The test
testMultilingualBookBreadcrumbBuilder
--loads the deepest page of one of the books
--constructs the breadcrumb for that page
--tests that each element in the breadcrumb shows the correct translation
Comment #186
mindbet commentedAttached is interdiff for 182-185
My apologies.
Comment #187
ghost of drupal pastThank you so much for taking this on.
This comment "// The node label will be the value for the current user's language." does not seem correct to me. The logic is complex, let's just call it the "current language".
Comment #188
ayushmishra206 commentedMade the changes requested in #187. Please Review
Comment #189
paulocsFixing drupal code standard.
Comment #190
mindbet commentedFixing an error in a comment, sorry.
Comment #192
joel_osc commentedI have tried this patch and translated books are largely working, many thanks to everyone that has contributed to this patch. I am seeing an issue where my base language is En and the translation language is Fr - when I view a book node in Fr the book navigation block shows the link titles in Fr (properly) but they are actually linked to the En node url. I managed to (hack?) fix it like this in BookManager.php:
I am wondering (a) if anyone else is seeing this issue and (b) should I potentially open a related issue in order to not muddy up this one? Cheers.
Comment #193
dbielke1986 commented@joel_osc
I can confirm this (https://www.drupal.org/project/drupal/issues/2470896#comment-13522365). This is the reason I am using patch #163
Comment #194
ghost of drupal past@joel_osc Thanks, I think it'd be great if you could add it to this patch with an appropriate test, I feel it might belong here.
Comment #195
paulocsSet back to needs work.
Comment #196
paulocsI'll do the job.
Comment #197
paulocsAdding the fix pointed on comment #192.
Comment #198
ghost of drupal pastThanks for adding it but don't you think it needs a test, too?
Comment #199
joseph.olstadIgnore this patch, it's just because my client is on 8.9.x still
this is patch 156 rerolled for 8.9.x
sorry no interdiff
Comment #200
joseph.olstadignore this patch, it is 156 rerolled for D8.9.7
just because my client is on 8.9.x still on 8.9.7
this is patch 156 rerolled for 8.9.7
sorry no interdiff
Comment #201
paulocsSet back to needs work because we need to write tests for patch #197
Comment #202
ridhimaabrol24 commentedAdding test. Please review!
Comment #203
paulocsHey @ridhimaabrol24, I see that you added a test.
The thing is that patch #197 already has test to cover the translation. What we need now is a test that verifies if the /book page is listing the right links with the correct language parameter. See comment #192 and #198.
Comment #204
ridhimaabrol24 commentedHey @paulocs. The test I added is verifying whether the book links and title are dispayed in the correct language. This test actually tests the bug in this issue.
It may be possible to add this method to an already existing test class rather than adding a new one but the method is actually testing the bug in this issue only.
Comment #205
ridhimaabrol24 commentedThe test added in #197 is a Kernel test but we will need a functional test to check the links and the node title on the browser. Please let me know your views.
Comment #206
joseph.olstadPlease ignore this patch, it is 156 rerolled for D8.9.9
just because my client is on 8.9.x still on 8.9.9
this is patch 156 rerolled for 8.9.9
sorry no interdiff
Comment #207
rachel_norfolkhey Jospeh.olstad - if you created a child issue of this one, saying that it was a back port of this issue, you could add your patches there as they are updated here. Would keep the scope of this issue nice and tight whilst allowing you to support your client.
You never know, the back post might even prove to be a worthwhile thing to be committed...
Comment #208
joseph.olstad@rachel_norfolk, patch 202 looks ready to me, we have a patch that has tests, proof that the patch is indeed fixing something, if there's a followup issue I'd ask that others open a new issue for that and provide their patches or forks for review. We could then finalize the backports for this issue.
Comment #209
ghost of drupal pastI will carry this patch home.
I believe we do not need a browser test -- those should be rare and either for raw functionality or for JS. Instead, we can assert the generated urls in the tree have the correct language so we can end up with a much faster kernel test.
Since this issue is extremely long and, I respectfully would like to ask everyone to just focus on getting it in and done and only after port it. Should you need intermittent patches please keep them elsewhere. Thanks.
Comment #210
ghost of drupal pastThis should be it. I was able to amend the existing test with a test asserting the rendered URLs are in the correct language. The necessary config is copied from
BlockUiTest, the rest is just the assert and since it is inside a conditional, making sure the assert actually ran.I do not think there is any BC concern with replacing the book tree URL string
"entity:node/$nid"with an actualUrlobject as this entity schema can not be printed raw, it must be passed to thelinkTwig function andTwigExtension::getLinkconverts URL strings with the exact same$url = Url::fromUri($url);code as used here. Further https://www.drupal.org/about/core/policies/core-change-policies/drupal-8...The closest ancestor to this is #190 as I have used a different fix to the problem described in #192 so an interdiff to that is attached. The previous fix is here. I also added an interdiff to #179 which was our last RTBC for the convenience of our committers.
I am keeping the issue assignment, I will see this issue home. I have the time for the foreseeable future.
This patch highlights the necessity of tranc-like functionality in core but that is most certainly a followup.
Comment #211
ghost of drupal pastComment #213
daffie commentedThe patch looks good to me. Only the added BookMultilingualTest feels more complicated then is needed. Just my perspective.
We are creating a tree of nodes. Could there be a bit of documentation of this tree. Something like in core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php or better. It is now all a bit confusing.
This method does a little bit more then only setting the current language to the given value. Could you explain what?
Do we really have to use recurse tree walk to test what we want to test. We have only one tree we are testing. Can we explicit test that tree. It makes reading and understanding what we are testing a lot simpler.
Are we are going to use SELF::LANGUAGE or 'de'. My preference would be to use 'de' everywhere.
Why is there a regex assertion here instead of a assertSame()? Please add documention why.
Why this one and only this one?
Could you add a comment about this line. What and why?
What are we testing on this line. Could you add a comment about the variable $found.
Could you add a comment about this line.
I would very much like to help by reviewing to get this patch committed.
Comment #214
ghost of drupal pastI wholeheartedly agree the BookMultilingualTest has grown overcomplicated and needed a good cleanup. I am not attaching an interdiff -- it's longer than the test itself so it's easier to read the test. The trees are explained and laid out explicitly, and all the tests are explicit instead of recursion or loops, I hope it's much more plain what's being tested.
No changes to anything else but the test. Interdiffs to 179/190 attached for the same reason as before although they are growing less and less useful with every iteration.
Comment #215
ghost of drupal pastI just realized we already set up the language negotiator for outgoing URLs so why not use it for determining the current language? Very little is needed, in fact, on top of what we already had. So: no more fake language negotiator. Also, I have cleaned up the
testMultilingualBookBreadcrumbBuilderto use the same assert astestMultilingualBookManagerand that found the bug #192 actually applies to the breadcrumb as well so I fixed that up.Comment #216
daffie commented@chx: The BookMultilingualTest looks great now. Just one question: where is the testing for the change to the class BookExport?
Edit: And the same for the testig of the changes to the class BookAdminEditForm.
Comment #217
ghost of drupal pastI have added a book export test but I am pushing back on the admin form test: there is no test for that form yet and also there are various bugs for that which all could use a test like #1184692: Unpublished books can't be reordered at admin/structure/book/[bookid] and #1169576: Book allows emptying node titles in admin/content/book/* (Notice: Trying to get property of non-object in node_page_title) so I filed an issue and linked it to all three.
As for the change in negotiation weights -- it made no sense to have a -10 weight when there's only method for each so I set them to 0 instead so the next person changing this doesn't need to wonder why it's -10.
Comment #218
larowlanThis is looking great, just a couple of minor changes
these will need to be 9.2.0 now (9.1.0 is out this week)
I think we typically use the FQCN in this type of comment
this could even just be $parent_book->toLink()
above we used |null but not here - we should make them consistent, I think without the |null means we don't have to do future cleanup - but not sure if we have a convention around this
we document one of these with |null but not the other.
We should be consistent.
any reason for this change, out of scope? I think it should be consistent (either use the $ for all, or don't)
so much cleaner
this is dead code, because we didn't make the argument optional.
Should we?
this is a really helpful comment, perhaps we could also get a representation of the tree in the comment something like this to make it abundantly clear (borrowed from another project, not the actual representation):
missing type-hints here
we can use scalar type hints here, we're doing so elsewhere so it should be consistent
Comment #219
ghost of drupal pastsedon the patch...)Generate a cache ID (cid) specific for this $bid, $link, language, and depth-- depth was already there, there is no$depthand similarly there is no$language.I didn't reroll all the interdiffs this time.
Comment #220
daffie commentedIt all looks good to me.
For all changes there are tests added.
With the exception of the changes to the class BookAdminEditForm, there is a followup issue #3185666: Test the book admin form.
All points of @larowlan have been addressed.
For me it is RTBC.
@chx: Nice work!
Comment #221
joseph.olstadGreat work @Charlie ChX Negyesi and @larowlan and others.
+1 super
Comment #222
larowlanOnly super-nits now, feel free to self-RTBC these changes
is this ever mixed?
nit, two spaces here
we double up here
Comment #223
ghost of drupal pastComment #225
naveed_jadoon commentedhi i got this on applying #223 patch for drupal 8.9.0, if someone can help that would be nice
Drupal\Core\Config\UnsupportedDataTypeConfigException: Invalid data type in config book.schema, found in filecore/modules/book/config/schema/book.schema.yml : A YAML file cannot contain tabs as indentation at line 36 (near " type: string"). in Drupal\Core\Config\FileStorage->read() (line 118 of core/lib/Drupal/Core/Config/FileStorage.php).
Comment #226
naveed_jadoon commentedComment #227
dbielke1986 commented@naveedahmadkhan.jadoon@gmail.com
The patch of #223 is not compatible with D8.9.x
You need to use the following one
#206
Comment #228
larowlanAdding issue credits for reviews
Comment #229
larowlanWent to commit this but there's some cspell and PHPCS violations
Whilst we're at it, can we also change the typehint for language manager param on book manager to use |null like the subsequent argument, so they're consistent
Comment #230
ghost of drupal pastI will self-RTBC this because after all this is just code styling (approved by larowlan). All changes are by phpcbf except for the langcude and |null as requested. However, I reverted some changes it made:
case 1: case 2:should not be indented with two extra spaces. They should be indented ascase 0is and so I have opted out of those fixes.Comment #232
larowlanFixed on commit to resolve phpcs automated issue mentioned in #230
Publishing the change record.
Congrats all.
This isn't eligible for backport because of the new deprecations.
Comment #233
ghost of drupal pastWhile not eligible for core commit, here's the patch re-rolled for 8.9.x for those who still run that -- and I suspect quite a few of us intend to do so for quite a while yet. Now is the time to do so. Conflicts were minimal.
Comment #234
bserem commentedHighly discouraged and not fully tested, but attached is a patch for Drupal 8.8.12 as requested by a site that hasn't yet updated to 8.9 (they run an older open social version).
Don't say you weren't warned, use at your own risk.
Comment #235
raman.b commentedAnyone encountered the following exception after this got committed?
"Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: "You have requested a non-existent service "language.manager". Did you mean this: "language_manager"?"
Created #3188519: "Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: "You have requested a non-existent service "language.manager". Did you mean this: "language_manager"?"
Comment #236
ghost of drupal past#3188519: "Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: "You have requested a non-existent service "language.manager". Did you mean this: "language_manager"?" has been fixed, sorry for the typo.
Comment #237
joseph.olstadReroll for 8.9.x, I have a client using this.
I took the same patch as 233 and just did a search for 'language.manager' and replaced the one instance
as per the issue noted just above
Comment #238
joseph.olstad***EDIT*** oops comment, removing it.
Comment #239
joseph.olstadComment #241
dbielke1986 commentedWith patch 233 we have a critical issue for D8:
This is a huge issue when you try to create customer documentation were unpublished nodes gets exported.
Comment #242
dbielke1986 commentedPS: Patch from #199 is working fine!
Hopefully Drupal 9.2 is working fine with the implemented version.
Can somebody try it out?
Comment #243
qusai taha commentedReroll for Drupal 9.1.10.
is working fine for me.
Comment #244
joaoclobocar commentedOn Drupal 9.1.10, I had to modify from language.manager to language_manager before applying the patch.
Comment #245
berdirThat is a bug, not related to 9.1/9.2, I assume you subclassed that class in your project and it triggers the BC layer. That part isn't tested. Please create a new issue to fix that and reference it here.
Edit: That was fixed in 9.2: #3188519: "Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: "You have requested a non-existent service "language.manager". Did you mean this: "language_manager"?". And maybe you didn't actually have a subclass, more likely you just didn't clear the cache.
Comment #246
ahmad abbad commented#244 works for me on Core 9.1.8
Comment #247
rachel_norfolkThanks for comments, Ahmad. So that the maintainers can understand in what way it "works for me", can you include a description of what you tested and, if possible, show some evidence of the change making a positive difference? Screenshots are usually the easiest way to do this - before and after applying the patch.
Have a read of https://www.drupal.org/community/contributor-guide/task/manually-test-a-... for more info.
(this is the stuff that's needed to ensure you get correctly credited for your work!)
Comment #248
dbielke1986 commentedI created a new bug in the core (https://www.drupal.org/project/drupal/issues/3228274) because the issue I found in #244 is now the harsh reality... achrived/unpublished nodes gets into the htm export....
Comment #249
joseph.olstad