1 views_handler_field_file_icon.inc | protected views_handler_field_file_icon::getIconName($uri) |
Map file extensions to Phosphor icons.
Parameters
string $uri: The original file path.
Return value
string: The name of an icon file, as expected by icon().
File
- core/
modules/ file/ views/ views_handler_field_file_icon.inc, line 128 - Definition of views_handler_field_file_icon.
Class
Code
protected function getIconName($uri) {
// If there's no 1:1 icon name match for the extension, map to one. It's
// possible that modules or themes provide additional file icons, so this
// only acts as a fallback for some common types.
$mapping = array(
'docx' => 'doc',
'gz' => 'archive',
'jpeg' => 'jpg',
'odt' => 'text',
'pptx' => 'ppt',
'tar' => 'archive',
'xlsx' => 'xls',
);
$extension = pathinfo($uri, PATHINFO_EXTENSION);
if (icon_get_path('file-' . $extension)) {
$icon_name = 'file-' . $extension;
}
elseif (array_key_exists($extension, $mapping)) {
$icon_name = 'file-' . $mapping[$extension];
}
else {
// If the extension has a more specific mimetype, use that type prefix.
$mime_type = file_get_mimetype($uri);
$mime_parts = explode('/', $mime_type);
if (count($mime_parts) && in_array($mime_parts[0], array(
'image',
'video',
'audio',
'text',
))) {
$icon_name = 'file-' . $mime_parts[0];
}
}
// Fallback to the generic icon if there are no other matches.
if (!isset($icon_name)) {
$icon_name = 'file';
}
return $icon_name;
}