public static function BlazyUtil::buildUri in Blazy 8.2
Returns the URI from the given image URL, relevant for unmanaged files.
1 call to BlazyUtil::buildUri()
- BlazyFilter::getImageItemFromImageSrc in src/
Plugin/ Filter/ BlazyFilter.php - Returns the faked image item from SRC.
File
- src/
BlazyUtil.php, line 73
Class
- BlazyUtil
- Provides Blazy utilities.
Namespace
Drupal\blazyCode
public static function buildUri($image_url) {
if (!UrlHelper::isExternal($image_url) && ($normal_path = UrlHelper::parse($image_url)['path'])) {
// If the request has a base path, remove it from the beginning of the
// normal path as it should not be included in the URI.
$base_path = \Drupal::request()
->getBasePath();
if ($base_path && strpos($normal_path, $base_path) === 0) {
$normal_path = str_replace($base_path, '', $normal_path);
}
$public_path = Settings::get('file_public_path', 'sites/default/files');
// Only concerns for the correct URI, not image URL which is already being
// displayed via SRC attribute. Don't bother language prefixes for IMG.
if ($public_path && strpos($normal_path, $public_path) !== FALSE) {
$rel_path = str_replace($public_path, '', $normal_path);
return file_build_uri($rel_path);
}
}
return FALSE;
}