Skip to content

Commit

Permalink
Merge pull request #18 from d3yii2/d3filesprewieBug
Browse files Browse the repository at this point in the history
Fixed bug
  • Loading branch information
uldisn authored Oct 8, 2019
2 parents a8e400f + 47d355e commit b93c3a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
13 changes: 4 additions & 9 deletions views/d3files/_modal_button.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

use d3yii2\d3files\widgets\D3FilesPreviewWidget;
use d3yii2\d3files\widgets\D3FilesWidget;
use d3yii2\pdfobject\widgets\PDFObject;
use eaBlankonThema\widget\ThModal;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\helpers\Url;

/**
* @var string $icon
Expand All @@ -16,8 +12,7 @@
* @var int $modelId
*/

$file = D3FilesWidget::getFirstFileHavingExt($fileList, 'pdf');

$attrs = D3FilesPreviewWidget::getPreviewModalButtonAttributes($modelId, $file, $fileList, $urlPrefix);

echo Html::a('<span class="' . $icon . '"></span>', 'javascript:void(0)', $attrs);
if($file = D3FilesWidget::getFirstFileHavingExt($fileList, 'pdf')) {
$attrs = D3FilesPreviewWidget::getPreviewModalButtonAttributes($modelId, $file, $fileList, $urlPrefix);
echo Html::a('<span class="' . $icon . '"></span>', 'javascript:void(0)', $attrs);
}
8 changes: 4 additions & 4 deletions widgets/D3FilesWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use d3yii2\d3files\D3Files;
use d3yii2\d3files\models\D3files as ModelD3Files;
use Exception;
use ReflectionException;
use Yii;
use yii\base\Widget;
use yii\db\ActiveRecord;
Expand All @@ -29,6 +28,8 @@
* @var string $urlPrefix
* @var string VIEW_DROPDOWN_LIST
* @var string VIEW_FILES_LIST
*
* @property array $viewParams
*/
class D3FilesWidget extends Widget
{
Expand Down Expand Up @@ -69,7 +70,6 @@ class D3FilesWidget extends Widget
public const VIEW_FILES_LIST = 'files-list';

/**
* @throws ReflectionException
* @throws \yii\db\Exception
* @throws Exception
*/
Expand Down Expand Up @@ -170,15 +170,15 @@ public static function getFileExtension(array $file): string
* @param string $extension
* @return array|null
*/
public static function getFirstFileHavingExt(array $files, string $extension): ?array
public static function getFirstFileHavingExt(array $files, string $extension): array
{
foreach ($files as $file) {
$fileExtension = strtolower(pathinfo($file['file_name'], PATHINFO_EXTENSION));
if ($extension === $fileExtension) {
return $file;
}
}
return null;
return [];
}

/**
Expand Down

0 comments on commit b93c3a3

Please sign in to comment.