/yii2-file-icons

Widget for getting the font-icon for file extension

Primary LanguagePHPBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

File icons widget for Yii2

Widget for getting the font-icon for file extension

Build Status Latest Stable Version Latest Unstable Version License

Installation

Run command

composer require black-lamp/yii2-file-icons

or add

"black-lamp/yii2-file-icons": "^1.0.0"

to the require section of your composer.json.

Using

Example of using

$widget = \bl\files\icons\FileIconWidget::begin([
    'icons' => [
        'txt' => [
            'icon' => \yii\helpers\Html::tag('i', '', ['class' => 'icon-file-txt'])
        ],
        'groups' => [
            [
                'extensions' => ['jpg', 'png', 'gif'],
                'icon' => \yii\helpers\Html::tag('i', '', ['class' => 'icon-picture'])
            ],
        ]
    ]
]);
echo $widget->getIcon('image.jpg');
$widget->end();

Method FileIconWidget::getIcon() takes file extension, file name or full path to file and returns icon for file extension. Icon - method gets from configuration array. If icon not found in configuration array method returns empty icon. Empty icon value gets from emptyIcon widget option.

Widget configuration properties

Option Description Type Default
icons Array with configuration for file extensions and icons array -
useDefaultIcons If set true - widget will be user default icons for files boolean false
emptyIcon If icon will not be found if icons array or in defaul icons set - value from this property will be returned string 'Icon for this extension not found!'

Default icon set

If you set widget option useDefaultIcons in true - method FileIconWidget::getIcon() will be returns default icons for file extensions. Also you can override default icons if you dont't wont to use default icon for curren file extension. Default icon set

<i class="file-text"></i>
<i class="file-pdf"></i>
<i class="file-power-point"></i>
<i class="file-archive"></i>
<i class="file-word"></i>
<i class="file-excel"></i>
<i class="file-picture"></i>
<i class="file-video"></i>
<i class="file-code"></i>

or using \bl\files\icons\helpers\IconHelper

IconHelper::icon('text');
IconHelper::icon('pdf');
IconHelper::icon('power-point');
IconHelper::icon('archive');
IconHelper::icon('word');
IconHelper::icon('excel');
IconHelper::icon('picture');
IconHelper::icon('video');
IconHelper::icon('code');