|
|
|
|
@ -19,6 +19,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
use Drupal\Core\Database\Connection; |
|
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
|
|
|
use Drupal\node\NodeTypeInterface; |
|
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse; |
|
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MetadataProfileController extends ControllerBase { |
|
|
|
|
|
|
|
|
|
@ -162,6 +166,16 @@ class MetadataProfileController extends ControllerBase {
|
|
|
|
|
|
|
|
|
|
$metadata_profile = $this->getMetadataProfile(); |
|
|
|
|
|
|
|
|
|
$entity = $this->routeMatch->getParameter($this->entityType); |
|
|
|
|
$build['download'] = [ |
|
|
|
|
'#type' => 'link', |
|
|
|
|
'#title' => $this->t('Download profile'), |
|
|
|
|
'#url' => $entity->toUrl('metadata-download'), |
|
|
|
|
'#attributes' => [ |
|
|
|
|
'class' => ['button', 'button--primary'], |
|
|
|
|
], |
|
|
|
|
'#weight' => -10, |
|
|
|
|
]; |
|
|
|
|
$build['summary_table'] = [ |
|
|
|
|
'#type' => 'container', |
|
|
|
|
'#attributes' => ['class' => ['scrolling-table-container']], |
|
|
|
|
@ -867,27 +881,43 @@ class MetadataProfileController extends ControllerBase {
|
|
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
|
|
|
|
* The file download response. |
|
|
|
|
*/ |
|
|
|
|
public function download() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function download(NodeTypeInterface $node_type) { |
|
|
|
|
// Rebuild your state from the entity |
|
|
|
|
$this->entityBundle = $node_type->id(); |
|
|
|
|
$this->entityTypeBundleOf = $node_type->getEntityType()->getBundleOf(); |
|
|
|
|
|
|
|
|
|
$contentType = $this->entityBundle; |
|
|
|
|
$entityKey = $this->entityTypeBundleOf; |
|
|
|
|
|
|
|
|
|
$headers = $this->getHeaders(); |
|
|
|
|
$metadata_profile = $this->getMetadataProfile(); |
|
|
|
|
$rows = $this->getRows($metadata_profile); |
|
|
|
|
$rows = $this->sanitizeRowsForCSV($rows); |
|
|
|
|
|
|
|
|
|
$filename_slug = "{$entityKey}__{$contentType}.csv"; |
|
|
|
|
$filename = $this->fileSystem->getTempDirectory() . '/' . $filename_slug; |
|
|
|
|
// Write file to temporary filesystem. |
|
|
|
|
|
|
|
|
|
if (file_exists($filename)) { |
|
|
|
|
$this->fileSystem->delete($filename); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$fh = fopen($filename, 'w'); |
|
|
|
|
fputcsv($fh, $headers); |
|
|
|
|
foreach ($rows as $row) { |
|
|
|
|
fputcsv($fh, $row); |
|
|
|
|
} |
|
|
|
|
fclose($fh); |
|
|
|
|
$request = new Request(['file' => $filename_slug]); |
|
|
|
|
return $this->fileDownloadController->download($request, 'temporary'); |
|
|
|
|
|
|
|
|
|
$response = new BinaryFileResponse($filename); |
|
|
|
|
$response->setContentDisposition( |
|
|
|
|
ResponseHeaderBag::DISPOSITION_ATTACHMENT, |
|
|
|
|
$filename_slug |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return $response; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function formatFacets(array $field_profile) { |
|
|
|
|
|