forked from inspiredminds/contao-isotope-pdf-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a custom format option (inspiredminds#7)
- Loading branch information
Showing
18 changed files
with
142 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor/ | ||
/composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
|
||
InspiredMinds\ContaoIsotopePdfTemplatesBundle\: | ||
resource: ../src | ||
exclude: ../src/{ContaoManager,DependencyInjection,Event,Isotope,Resources} | ||
|
||
InspiredMinds\ContaoIsotopePdfTemplatesBundle\EventListener\DataContainer\IsoDocumentListener: | ||
public: true | ||
arguments: | ||
- '%kernel.project_dir%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the ContaoIsotopePdfTemplatesBundle bundle. | ||
* | ||
* (c) inspiredminds | ||
* | ||
* @license LGPL-3.0-or-later | ||
*/ | ||
|
||
use InspiredMinds\ContaoIsotopePdfTemplatesBundle\Isotope\Model\Document\Template; | ||
use Isotope\Model\Document; | ||
|
||
Document::registerModelType('template', Template::class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/EventListener/DataContainer/TemplateCustomFormatSaveListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the ContaoIsotopePdfTemplatesBundle bundle. | ||
* | ||
* (c) inspiredminds | ||
* | ||
* @license LGPL-3.0-or-later | ||
*/ | ||
|
||
namespace InspiredMinds\ContaoIsotopePdfTemplatesBundle\EventListener\DataContainer; | ||
|
||
use Contao\CoreBundle\ServiceAnnotation\Callback; | ||
use Contao\StringUtil; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
/** | ||
* @Callback(table="tl_iso_document", target="fields.pdfFormatCustom.save") | ||
*/ | ||
class TemplateCustomFormatSaveListener | ||
{ | ||
private RequestStack $requestStack; | ||
private TranslatorInterface $translator; | ||
|
||
public function __construct(RequestStack $requestStack, TranslatorInterface $translator) | ||
{ | ||
$this->requestStack = $requestStack; | ||
$this->translator = $translator; | ||
} | ||
|
||
public function __invoke($value): string | ||
{ | ||
$request = $this->requestStack->getCurrentRequest(); | ||
$values = StringUtil::deserialize($value, true) + ['', '']; | ||
|
||
if (!array_filter($values) && !$request->request->get('pdfFormat')) { | ||
throw new \Exception($this->translator->trans('ERR.missingCustomPdfFormat', [], 'contao_default')); | ||
} | ||
|
||
return serialize(array_map('floatval', $values)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.