Closed (fixed)
Project:
Drupal core
Version:
10.0.x-dev
Component:
language system
Priority:
Minor
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
24 Apr 2020 at 22:13 UTC
Updated:
14 Feb 2023 at 11:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
stefanos.petrakisHere is the patch.
Comment #3
stefanos.petrakisComment #4
stefanos.petrakisAnother issue came up while writing unit tests, when the languageManager is not set.
Updated the patch and issue's title.
Comment #5
jungleCode above is from the patch
a) Based on the comments of
\Drupal\language\LanguageNegotiationMethodInterface::getLangcode()above, returningNULLis inapplicable. And the type hinting of the interface should be updated tostring|falseorstring|bool, not sure which one is applicable, isfalsea type? but found usages in core.b) Or update the comment to say string or NULL, and change
@return stringto @return string|nullAnd the whole method might need to be rewritten
a) $langcode = $request->query->get(static::QUERY_PARAMETER); is possible to return NULL.
b) the const name
QUERY_PARAMETERis too generic, it's not obvious relevant tolangcodeorlanguage_content_entity-- the real value. But it's out of the scope here.Comment #6
stefanos.petrakisThanks for the review!
Regarding (1): See ongoing discussion over at #3126127: Fix LanguageNegotiationMethodInterface::getLangcode() result docblock, if you haven't seen that already. It may be that the docblock could be modified to extend the range of return value types.
Regarding (2): That is a different topic, again, more relevant to #3126127: Fix LanguageNegotiationMethodInterface::getLangcode() result docblock, the code changes I suggest are only focusing on errors coming up during Unit Testing, a WIP from #3130107: Extend unit test coverage for LanguageNegotiationContentEntity
Comment #11
larowlanIs this still an issue?
Comment #12
stefanos.petrakisYes, still an issue, albeit on the unit level.
The rest of the
@LanguageNegotiationplugins have defensive code in place for$request(when they use it) and sometimes even for the$this->languageManager.This is really not a big issue, code from core that calls
getLangcode()usually has some checks implemented beforehand.However, since this is a public method, I believe it would be good to add the defenses and keep aligned with the rest of the codes found under
core/modules/language/src/Plugin/LanguageNegotiationComment #14
larowlanAccording to the API, this should return a string or FALSE, not NULL - so I think we should update this.
As this is a bug, we need a failing test demonstrating the issue. And whilst
\Drupal\Tests\language\Functional\LanguageNegotiationContentEntityTestmight seem a logical place for this, I think we can test it in a Unit test to reproduce the reported issue here.Comment #15
medha kumariRerolled the patch #4 in Drupal 9.5.x and changes comment #14.
Comment #16
stefanos.petrakisPicking this up; gonna work against 10.1.x to address comments in #14, including the work from #15
Comment #18
stefanos.petrakisTests (including new ones) are green, hiding patch files and this is ready for a review again. This time via the MR.
Comment #19
larowlanCouple of minor comments on the MR
Comment #20
stefanos.petrakisThanks for the review, I fixed one more incompatibility issue with the returning value. And extended the tests with 2 more cases, I hope this is good now!
Comment #21
larowlanThis looks good to me, thanks @stefanos.petrakis 🙌
Comment #22
alexpottI don't think we should be changing the return value here. I think we should open a separate issue to discuss the fact the interface docs and the implementations (at least all the ones I've checked) do different things. Personally I think we should always err on the side of changing the docs rather code.
Comment #23
stefanos.petrakisThis one is waiting on #3126127: Fix LanguageNegotiationMethodInterface::getLangcode() result docblock
Comment #24
stefanos.petrakisNow that #3126127: Fix LanguageNegotiationMethodInterface::getLangcode() result docblock is fixed and there is no documentation-inconsistency aspect, this here issue can move forward. Setting it back to NR since my latest changes set the return values to NULL (as was originally) instead of FALSE. That way the change-set focuses only on the reported errors (see description).
Comment #25
stefanos.petrakisComment #26
larowlanThanks @stefanos.petrakis for creating the separate issue and following this one through
This looks good to me
Comment #27
alexpottCommitted and pushed 5738144ad9 to 10.1.x and 681c999fea to 10.0.x. Thanks!
Not backporting to 9.5.x because the test needs changing because it has property typehints and we still support PHP 7.3 there and this is a minor bug.