Deprecation: #107413 - PathUtility getRelativePath(to) methods
See forge#107413
Description
The following methods in
\TYPO3\ have been
marked as deprecated and will be removed in TYPO3 v15.0:
PathUtility:: get Relative Path () PathUtility:: get Relative Path To ()
These methods are no longer needed, as TYPO3's path handling has been simplified due to the unification of the entry point URLs.
Since TYPO3 v13, both frontend and backend use the same main entry point
(htdocs/), making relative path calculations obsolete.
Impact
Calling these methods will trigger a PHP deprecation warning. They will continue to work as before until they are removed in TYPO3 v15.0.
Affected installations
TYPO3 installations with custom extensions or code that directly call the deprecated methods are affected:
PathUtility:: get Relative Path () PathUtility:: get Relative Path To ()
The extension scanner will report any usage as a strong match.
Migration
Instead of calculating relative paths manually, use absolute paths or the appropriate TYPO3 APIs for path handling:
- Use
Generalfor extension resourcesUtility:: get File Abs File Name () - Use the
EXT:prefix when referencing extension resources - Use
Pathfor public extension resourcesUtility:: get Public Resource Web Path () - Reference paths relative to the public web path of the TYPO3 installation
use TYPO3\CMS\Core\Utility\PathUtility;
$relativePath = PathUtility::getRelativePath($sourcePath, $targetPath);
$relativeToPath = PathUtility::getRelativePathTo($absolutePath);
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
// Use absolute paths or appropriate TYPO3 APIs
$absolutePath = GeneralUtility::getFileAbsFileName(
'EXT:my_extension/Resources/Public/file.js'
);
$webPath = PathUtility::getPublicResourceWebPath(
'EXT:my_extension/Resources/Public/file.js'
);