Skip to content

Commit

Permalink
[TASK] Avoid objectManager usage in PdfView class
Browse files Browse the repository at this point in the history
  • Loading branch information
derhansen committed Dec 15, 2021
1 parent d7fe818 commit 69c5ac7
Showing 1 changed file with 17 additions and 36 deletions.
53 changes: 17 additions & 36 deletions Classes/View/PdfView.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
/* * *************************************************************

/****************************************************************
* Copyright notice
*
* (C) 2015 Mittwald CM Service GmbH & Co. KG <[email protected]>
* (C) Mittwald CM Service GmbH & Co. KG <[email protected]>
*
* All rights reserved
*
Expand All @@ -21,7 +22,7 @@
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */
***************************************************************/

namespace Mittwald\Web2pdf\View;

Expand All @@ -32,17 +33,8 @@
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Fluid\View\StandaloneView;


/**
* PDFView
*
* @author Kevin Purrmann <[email protected]>, Purrmann Websolutions
* @package Mittwald
* @subpackage Web2Pdf\View
*/
class PdfView
{

Expand All @@ -64,11 +56,6 @@ class PdfView
*/
protected $pdfLinkUtility;

/**
* @var ObjectManagerInterface
*/
protected $objectManager;

/**
* PdfView constructor.
* @param ModuleOptions $options
Expand All @@ -78,13 +65,11 @@ class PdfView
public function __construct(
ModuleOptions $options,
FilenameUtility $fileNameUtility,
PdfLinkUtility $pdfLinkUtility,
ObjectManagerInterface $objectManager
PdfLinkUtility $pdfLinkUtility
) {
$this->options = $options;
$this->fileNameUtility = $fileNameUtility;
$this->pdfLinkUtility = $pdfLinkUtility;
$this->objectManager = $objectManager;
}


Expand Down Expand Up @@ -160,20 +145,17 @@ protected function getPdfObject(): Mpdf
$topMargin = ($this->options->getPdfTopMargin()) ? $this->options->getPdfTopMargin() : '15';
$styleSheet = ($this->options->getPdfStyleSheet()) ? $this->options->getPdfStyleSheet() : 'print';

/* @var $pdf Mpdf */
$pdf = $this->objectManager->get(
Mpdf::class, [
'format' => $pageFormat,
'default_font_size' => 12,
'margin_left' => $leftMargin,
'margin_right' => $rightMargin,
'margin_top' => $topMargin,
'margin_bottom' => $bottomMargin,
'orientation' => $pageOrientation,
'tempDir' => Environment::getVarPath() . '/web2pdf',
'fontDir' => ExtensionManagementUtility::extPath('web2pdf') . 'Resources/Public/Fonts',
]
);
$pdf = new Mpdf([
'format' => $pageFormat,
'default_font_size' => 12,
'margin_left' => $leftMargin,
'margin_right' => $rightMargin,
'margin_top' => $topMargin,
'margin_bottom' => $bottomMargin,
'orientation' => $pageOrientation,
'tempDir' => Environment::getVarPath() . '/web2pdf',
'fontDir' => ExtensionManagementUtility::extPath('web2pdf') . 'Resources/Public/Fonts',
]);

$pdf->SetMargins($leftMargin, $rightMargin, $topMargin);

Expand All @@ -190,8 +172,7 @@ protected function getPdfObject(): Mpdf
*/
protected function getPartial($templateName, $arguments = array()): string
{
/* @var $partial \TYPO3\CMS\Fluid\View\StandaloneView */
$partial = $this->objectManager->get(StandaloneView::class);
$partial = GeneralUtility::makeInstance(StandaloneView::class);
$partial->setLayoutRootPaths($this->options->getLayoutRootPaths());
$partial->setPartialRootPaths($this->options->getPartialRootPaths());
$partial->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(end($partial->getPartialRootPaths())) . 'Pdf/' . ucfirst($templateName) . '.html');
Expand Down

0 comments on commit 69c5ac7

Please sign in to comment.