getAbsolutePath returns wrong path when module is out of magento root path
Magento new PSR-4 and registration.php features are great and allow to set modules out of the Magento root folder. This works smoothly for classes but it does not work when it has to find source files like .phtml, .js or .css.
The problem comes from the Magento\Framework\Filesystem\Driver\File::getRelativePath() method. If the module is out of the Magento root then the Magento root path is added at the beginning of an already correct absolute path. That return a completely wrong path and in consequence files are not found. From my point of view, if the path already contains a "/" at the beginning it should be treated as absolute path and there is no need to add the magento root at the beginning.
A possible solution would be like that:
public function getAbsolutePath($basePath, $path, $scheme = null)
{
if ($path[0] == "/") {
return $path;
}
return $this->getScheme($scheme) . $basePath . ltrim($this->fixSeparator($path), '/');
}
Related: https://github.com/magento/magento2/pull/1490
That PR already contained a fix for the issue (along with fixing the behavior of getRelativePath), but unfortunately the PR was rejected, even though I also think the current behavior is broken and those methods should work also for files outside of the Magento base directory.
Well, it is a pity that the PR was rejected. Hopefully Magento guys have an alternative solution to fix this issue.
@jalogut Please, provide the used version. If the problem is actual for a specific tag, please, specify it and be sure that the latest update was used.
According to contributor guide, tickets without response for two weeks should be closed. Please feel free to reopen if it's needed.