magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

getAbsolutePath returns wrong path when module is out of magento root path

Open jalogut opened this issue 10 years ago • 4 comments

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), '/');
}

jalogut avatar Feb 08 '16 09:02 jalogut

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.

Vinai avatar Feb 08 '16 09:02 Vinai

Well, it is a pity that the PR was rejected. Hopefully Magento guys have an alternative solution to fix this issue.

jalogut avatar Feb 08 '16 10:02 jalogut

@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.

palamar avatar Jun 22 '16 17:06 palamar

According to contributor guide, tickets without response for two weeks should be closed. Please feel free to reopen if it's needed.

palamar avatar Jul 07 '16 15:07 palamar