src/Utility/FileUpload.php
private function getIconPath(FileStorage $entity, string $version) : string
    {
        $imgSizes = (array)Configure::read(sprintf('FileStorage.imageSizes.%s', $entity->get('model')));

        // no image sizes, return default
        if (empty($imgSizes)) {
            return Utility::getFileTypeIcon($entity->get('extension'));
        }

        // sort by size, biggest first and get current version position in the array
        $position = array_search($version, array_keys(Hash::sort($imgSizes, 'width')), true);

        // no position, return default
        if (false === $position) {
            return Utility::getFileTypeIcon($entity->get('extension'));
        }

        $iconSizes = [512, 48, 32, 16];
        // traversing recursively through the icon sizes until it finds the closest one by key position
        $funcGetIconSize = function (int $pos) use ($iconSizes, &$funcGetIconSize) {
            if (! array_key_exists($pos, $iconSizes)) {
                return $funcGetIconSize($pos - 1);
            }

            return $iconSizes[$pos];
        };

        $result = Utility::getFileTypeIcon($entity->get('extension'), sprintf('%dpx', $funcGetIconSize($position)));

        $result = $this->getUrlHelper()->image($result);

        return $result;
    }
private function getIconPath(FileStorage $entity, string $version) : string
    {
        $imgSizes = (array)Configure::read(sprintf('FileStorage.imageSizes.%s', $entity->get('model')));

        // no image sizes, return default
        if (empty($imgSizes)) {
            return Utility::getFileTypeIcon($entity->get('extension'));
        }

        // sort by size, biggest first and get current version position in the array
        $position = array_search($version, array_keys(Hash::sort($imgSizes, 'width')), true);

        // no position, return default
        if (false === $position) {
            return Utility::getFileTypeIcon($entity->get('extension'));
        }

        $iconSizes = [512, 48, 32, 16];
        // traversing recursively through the icon sizes until it finds the closest one by key position
        $funcGetIconSize = function (int $pos) use ($iconSizes, &$funcGetIconSize) {
            if (! array_key_exists($pos, $iconSizes)) {
                return $funcGetIconSize($pos - 1);
            }

            return $iconSizes[$pos];
        };

        $result = Utility::getFileTypeIcon($entity->get('extension'), sprintf('%dpx', $funcGetIconSize($position)));

        $result = $this->getUrlHelper()->image($result);

        return $result;
    }
private function getIconPath ( FileStorage $ entity , string $ version ) : string { $ imgSizes = ( array ) Configure :: read ( sprintf ( 'FileStorage.imageSizes.%s' , $ entity -> get ( 'model' ) ) ) ; // no image sizes, return default if ( empty ( $ imgSizes ) ) { return Utility :: getFileTypeIcon ( $ entity -> get ( 'extension' ) ) ; } // sort by size, biggest first and get current version position in the array $ position = array_search ( $ version , array_keys ( Hash :: sort ( $ imgSizes , 'width' ) ) , true ) ; // no position, return default if ( false === $ position ) { return Utility :: getFileTypeIcon ( $ entity -> get ( 'extension' ) ) ; } $ iconSizes = [ 512 , 48 , 32 , 16 ] ; // traversing recursively through the icon sizes until it finds the closest one by key position $ funcGetIconSize = function ( int $ pos ) use ( $ iconSizes , & $ funcGetIconSize ) { if ( ! array_key_exists ( $ pos , $ iconSizes ) ) { return $ funcGetIconSize ( $ pos - 1 ) ; } return $ iconSizes [ $ pos ] ; } ; $ result = Utility :: getFileTypeIcon ( $ entity -> get ( 'extension' ) , sprintf ( '%dpx' , $ funcGetIconSize ( $ position ) ) ) ; $ result = $ this -> getUrlHelper ( ) -> image ( $ result ) ; return $ result ; }
Icon path getter.

@param \Burzum\FileStorage\Model\Entity\FileStorage $entity FileStorage entity
@param string $version Version name
@return string
Icon path getter .