function IconFinder::getFileFromUrl
Get filename from an URL source.
Because url to an image can be of various form, there is no extension validation, only scheme, the extractor must handle the constraints.
Parameters
string $scheme: The url scheme from parse_url().
string $path: The url path from parse_url().
string $source: The source.
Return value
array<string, array<string, string|null>> The file discovered.
1 call to IconFinder::getFileFromUrl()
- IconFinder::getFilesFromSources in core/
lib/ Drupal/ Core/ Theme/ Icon/ IconFinder.php - Create files from source paths.
File
-
core/
lib/ Drupal/ Core/ Theme/ Icon/ IconFinder.php, line 160
Class
- IconFinder
- Icon finder to discover files under specific paths or URLs.
Namespace
Drupal\Core\Theme\IconCode
private function getFileFromUrl(string $scheme, string $path, string $source) : array {
if (!in_array($scheme, UrlHelper::getAllowedProtocols(), TRUE)) {
$this->logger
->warning('Invalid icon source: @source', [
'@source' => $source,
]);
return [];
}
// Decode url to have cleaner filename.
$icon_id = pathinfo(urldecode($path), PATHINFO_FILENAME);
// Icon ID is used as index to avoid duplicates.
return [
$icon_id => [
'icon_id' => $icon_id,
'source' => $source,
'absolute_path' => $source,
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.