fix broken logic in CRM_Utils_System_DrupalBase::formatResourceUrl() #13400
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.
CRM_Utils_System_DrupalBase::formatResourceUrl() formats CSS or JS URLs to be passed to the CMS for aggregation.
It works fine for the most part, but has some broken logic when an absolute URL containing the $base_url is passed in (for example, from shoreditch extension).
Before
The URL path is checked via file_exists() to see if it's an internal file. Query string is stripped off later in the function. However, this check will always fail unless the query string is stripped off first. In addition, the path being checked is missing a slash between DRUPAL_ROOT and the path, so again the check will always fail. This results in the resource not being aggregated even though it could.
After
Strip off the query string and add the missing slash. If file is found, we set the $url reference. Resource aggregation works.
Comments
You might be wondering why there is a query string passed, which is then stripped off. This is because CRM_Core_Resources::addCacheCode() adds a cache-busting query string. It gets stripped off in favor of doing CSS/JS aggregation.