/** * Prepare Data Source * * @param array $dataSource * @return void */ public function prepareDataSource(array &$dataSource) { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as &$item) { $item[$this->getData('name')]['edit'] = ['href' => $this->urlBuilder->getUrl('umc/module/edit', ['id' => $item['safe_id']]), 'label' => __('Edit'), 'hidden' => false]; $rootDir = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR); foreach ($this->downloader->getDownloaderTypes() as $type) { $downloader = $this->downloader->getDownloader($type); $file = $downloader->getRelativePath($item['filename_id']); $file = $rootDir->getRelativePath(Settings::VAR_DIR_NAME . '/' . $file); if ($rootDir->isFile($file) && $rootDir->isReadable($file)) { $url = $this->urlBuilder->getUrl('umc/module/download', ['id' => $item['safe_id'], 'type' => $type]); $label = $downloader->getLabel(); } else { $url = '#'; $label = $downloader->getErrorLabel(); } $item[$this->getData('name')][$type] = ['href' => $url, 'label' => $label, 'hidden' => false]; } } } }