Skip to content

Commit ae1b394

Browse files
committed
Move formatFinderImage to standalone service
1 parent 2568f6b commit ae1b394

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

src/Classes/DataTable/DataTable.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,21 +295,7 @@ public function formatCheckbox($value, $rowData, $column): string
295295
*/
296296
public function formatFinderImage($value): string
297297
{
298-
if ( ! $value) {
299-
return '';
300-
}
301-
302-
$thumbUrl = $this->twigService->mediaFile($value, FinderConfig::DEFAULT_THUMB_TYPE, true);
303-
$url = $this->url->get('file', $value);
304-
305-
$style = 'background-image: url(' . $thumbUrl . ')';
306-
307-
return $this->tag->element('div', '', [
308-
'class' => 'thumb',
309-
'data-url' => $url,
310-
'data-thumb-url' => $thumbUrl,
311-
'style' => $style
312-
]);
298+
return $this->dataTableService->formatFinderImage($value);
313299
}
314300

315301
/**

src/Services/DataTable/DataTableService.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Exception;
88
use KikCMS\Classes\DataTable\DataTable;
99
use KikCMS\Classes\WebForm\DataForm\StorageData;
10+
use KikCMS\Config\FinderConfig;
1011
use KikCMS\Services\Util\QueryService;
1112
use Monolog\Logger;
1213
use KikCMS\Classes\Phalcon\Injectable;
@@ -74,6 +75,29 @@ public function addImageDirectly(int $fileId, DataTable $dataTable): ?int
7475
return $success ? $editId : null;
7576
}
7677

78+
/**
79+
* @param $value
80+
* @return string
81+
*/
82+
public function formatFinderImage($value): string
83+
{
84+
if ( ! $value) {
85+
return '';
86+
}
87+
88+
$thumbUrl = $this->twigService->mediaFile($value, FinderConfig::DEFAULT_THUMB_TYPE, true);
89+
$url = $this->url->get('file', $value);
90+
91+
$style = 'background-image: url(' . $thumbUrl . ')';
92+
93+
return $this->tag->element('div', '', [
94+
'class' => 'thumb',
95+
'data-url' => $url,
96+
'data-thumb-url' => $thumbUrl,
97+
'style' => $style
98+
]);
99+
}
100+
77101
/**
78102
* @param DataTable $dataTable
79103
* @param int $id

0 commit comments

Comments
 (0)