Skip to content
Snippets Groups Projects
Commit 00df32fb authored by Gaurav Kapoor's avatar Gaurav Kapoor Committed by Gaurav Kapoor
Browse files

Issue #3243259 by gaurav.kapoor: PDF and Docx file not getting downloaded

parent b26ae757
Branches
Tags
No related merge requests found
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Defines common functionality for Documentation Generator. * Defines common functionality for Documentation Generator.
*/ */
use \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; use Symfony\Component\HttpFoundation\BinaryFileResponse;
/** /**
* Implements hook_file_download(). * Implements hook_file_download().
...@@ -20,14 +20,19 @@ function documentation_generator_file_download($uri) { ...@@ -20,14 +20,19 @@ function documentation_generator_file_download($uri) {
&& ($user = \Drupal::currentUser()) && ($user = \Drupal::currentUser())
&& ($user->hasPermission('administer documentation generator')) && ($user->hasPermission('administer documentation generator'))
) { ) {
return [ $uri_download_headers = [
'Content-Description' => 'File Transfer', 'Content-Description' => 'File Transfer',
'Content-Disposition' => 'attachment; filename="' . $target . '"', 'Content-Disposition' => 'attachment; filename="' . $target . '"',
'Content-Type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'Content-Type' => \Drupal::service('file.mime_type.guesser')->guess($uri),
'Content-Transfer-Encoding' => 'binary', 'Content-Transfer-Encoding' => 'binary',
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
'Expires' => 0, 'Expires' => 0,
]; ];
$file = new BinaryFileResponse($uri, 200, $uri_download_headers, FALSE);
$file->send();
// Exit to avoid duplication of HTTP transmission.
exit();
} }
} }
......
...@@ -55,8 +55,8 @@ class SampleDocumentationPlugin extends DocumentationGeneratorChapterBase { ...@@ -55,8 +55,8 @@ class SampleDocumentationPlugin extends DocumentationGeneratorChapterBase {
$url = Url::fromUserInput('/admin/content')->setAbsolute()->toString(); $url = Url::fromUserInput('/admin/content')->setAbsolute()->toString();
// The '@paramter' string can be added to introduce paramters in the element content. // The '@paramter' string can be added to introduce paramters in the element
// It can be of type 'link' with other keys as 'text' and 'src'. // content. It can be of type 'link' with other keys as 'text' and 'src'.
$elements[] = [ $elements[] = [
'type' => 'paragraph', 'type' => 'paragraph',
'level' => 2, 'level' => 2,
......
...@@ -80,7 +80,7 @@ class PDF extends DocumentationGeneratorRenderBase implements ContainerFactoryPl ...@@ -80,7 +80,7 @@ class PDF extends DocumentationGeneratorRenderBase implements ContainerFactoryPl
$success = TRUE; $success = TRUE;
try { try {
file_save_data($output, 'private:// ' . $fileName); file_save_data($output, 'private://' . $fileName);
} }
catch (FileException $e) { catch (FileException $e) {
$success = FALSE; $success = FALSE;
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Drupal\Tests\documentation_generator\Unit\Controller; namespace Drupal\Tests\documentation_generator\Unit\Controller;
use Drupal\documentation_generator\Controller\OverviewController; use Drupal\documentation_generator\Controller\OverviewController;
use Drupal\forum\Form\Overview;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment