public function Presentation::iconView in Filebrowser 8.2
Same name and namespace in other branches
- 3.x src/Presentation.php \Drupal\filebrowser\Presentation::iconView()
File
- src/
Presentation.php, line 200
Class
Namespace
Drupal\filebrowserCode
public function iconView() {
/**
* @var \Drupal\Core\Image\Image $thumbnail
* @var \Drupal\filebrowser\Grid\Grid $grid_table
* @var DisplayFile $data
*/
$list_data = $this->dbFileList['data'];
$grids = [];
$this
->sortIconViewFiles($this->dbFileList['files']);
$height = $this->filebrowser->gridHeight;
$width = $this->filebrowser->gridWidth;
foreach ($this->dbFileList['files'] as $file_name => $data) {
// Skip dot folder
if ($file_name == ".") {
continue;
}
// File extension case
if ($file_name != ".." && $data->fileData->type == 'file' && $this->filebrowser->hideExtension) {
$pos = strrpos($data->displayName, ".");
$data->name = substr($data->displayName, 0, $pos);
}
// Check if we can create an image
if (empty($data->fileData->uri) || !\Drupal::service('image.factory')
->get($data->fileData->uri)
->isValid()) {
// create thumbnail from icon file
$thumbnail = $this->common
->iconGenerate($data->fileData->type, $data->fileData->mimetype, $height, $width);
}
else {
// create the styled thumbnail
$thumbnail = [
'#theme' => 'image_style',
'#style_name' => $this->filebrowser->gridImageStyle,
'#uri' => $data->fileData->uri,
'#alt' => 'image style',
'#title' => NULL,
'#width:' => null,
'#height:' => null,
'#attributes' => [],
];
}
$download_link = null;
$grids[] = [
'grid' => [
'#theme' => 'filebrowser_grid_item',
'#data' => [
'title' => $data->displayName == '..' ? $this
->t('Go up') : $data->displayName,
'type' => $data->fileData->type,
'thumbnail' => $thumbnail,
'download_link' => $download_link,
'new' => [
'#theme' => 'mark',
'#type' => $data->status,
],
'href' => $data->href,
'hide_title' => $this->filebrowser->gridHideTitle,
],
],
'file' => $data,
];
}
$options = [
'alignment' => $this->filebrowser->gridAlignment,
'columns' => $this->filebrowser->gridColumns,
'automatic_width' => $this->filebrowser->gridAutoWidth,
];
$grid_table = new Grid($grids, $options);
$items['grid_items'] = $grid_table
->get();
$items['options'] = $options;
$params = [
'actions' => !empty($this->formActions) ? $this->formActions : null,
'node' => $this->node,
'data' => $list_data,
];
return \Drupal::formBuilder()
->getForm('\\Drupal\\filebrowser\\Form\\GridActionForm', $items, $params);
}