-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IBX-952: Added chosen Location to Translation Choice form #1885
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say that because the user might not have access to the main location we should not treat it like a secure fallback. If in any of those cases location will be null then an error will occur.
@@ -85,7 +91,11 @@ function (Language $language) { | |||
$this->contentInfo, | |||
[ | |||
(new Target\Builder\VersionBuilder())->translateToAnyLanguageOf($languagesCodes)->build(), | |||
$this->locationService->loadLocation($this->contentInfo->mainLocationId), | |||
$this->locationService->loadLocation( | |||
$this->location !== null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we will have a location there is a need to reload it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this ChoiceLoader is not a service, it's initialized with the form so it shouldn't really be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContentEditTranslationChoiceLoader is a service. Of course, we could reload but what for? It looks not so good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is indeed a service then sure we shouldn't store it as a property 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikadamczyk It's not a service. It's built on demand, just like most choice loaders do.
I guess the issue could be that the current user does not have access to a Location
in current context, hence the reload. I do think though that it should be skipped if it's passed directly - relying on implicit security check would be bad anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we agreed, it is incorrectly registered as a service
@@ -50,14 +54,16 @@ public function __construct( | |||
?ContentInfo $contentInfo, | |||
LookupLimitationsTransformer $lookupLimitationsTransformer, | |||
array $languageCodes, | |||
LocationService $locationService | |||
LocationService $locationService, | |||
?Location $location |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?Location $location | |
?Location $location = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to always require this parameter and drop the LocationService
dependency as a result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from BC, I think this would be a good idea.
@mikadamczyk You are right, this is not fixing the root issue, only decreases chances of happening. Anyway this is still a valid PR because it makes the form being closer to actual context and not just rely on possibly completely different |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 2 questions posted in comments that I'd like to have answered before merging:
- Do we reload the
Location
object internally, if it has been passed directly via constructor? - Do we expect to make
$location
argument mandatory in Choice Loader? If yes, then should we deprecate$locationService
argument (as it's only purpose was to do the loading)?
Additionally, should we remove the ChoiceLoader service, as it should not (and cannot) be used as a service? If yes, then should it be a separate PR, or should we do so immediately?
@Steveb-p |
🧙♂️ Summoning @alongosz for architecture design decision |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null
as default, because we can't make it mandatory without a BC break. In terms of future direction that we could go is making it mandatory to passLocation
from calling code (i.e. when constructing the ChoiceLoader in question). This would then lead to removal ofLocationService
dependency in ChoiceLoader itself - instead developers would useLocationService
in calling code as necessary.Summoning @alongosz for architecture design decision
@Steveb-p I'm not really following what happens here, but from the clean code POV if you were to introduce Location
value so you can entirely drop dependency on LocationService
and costly loading of Repository data, I would always support that.
That said, it of course depends on the required changes to the calling code. If this is used only within the scope we see in the PR - it should be fine. If it's used elsewhere, then depends on such diff as well.
12df4e9
to
e436c4d
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Merged into |
We should consider the
Location
we are actually in to load the required languages as the user might not have access to mainLocation
but have access to secondary one.Related
ezplatform-page-builder
PR: https://github.com/ezsystems/ezplatform-page-builder/pull/826.Checklist:
$ composer fix-cs
)