Fix invalid asset resolution with numeric theme_id #7686
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are cases in which the theme ID is passed to the asset resolution, but the processing in this case doesn't handle numbers correctly. This has the direct effect of the system not finding valid template files, for example.
One case of a passed numeric theme ID is saving a widget instance, to create the layout update XML. Because the theme model is invalid, M2 will always resolve the template relative to
vendor/
(M2), never for third parties/themes.So the call would be equivalent to - say -
$this->getThemeProvider()->getThemeByFullPath('frontend/5')
, which, as much as I tried to think that there's some magic coversion happening somewhere, it wasn't the case, and the theme model was never found.This bug was hidden this much time because the validation of the theme model is done incorrectly, assuming it can sometimes be falsy, which is not the case, as the model is a result of
$themeCollection->getFirstItem()
, which will always be an object (so truthy). The ID needs to be checked instead.I'm possibly very wrong in my PR, or this is a pretty serious bug.