Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dennis Patzer
committed
Sep 24, 2019
1 parent
937915c
commit 0a8d41e
Showing
9 changed files
with
188 additions
and
4 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
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,111 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) 2019 Heimrich & Hannot GmbH | ||
* | ||
* @license LGPL-3.0-or-later | ||
*/ | ||
|
||
namespace HeimrichHannot\ListBundle\ConfigElementType; | ||
|
||
use Contao\Module; | ||
use HeimrichHannot\ListBundle\Item\ItemInterface; | ||
use HeimrichHannot\ListBundle\Model\ListConfigElementModel; | ||
use HeimrichHannot\UtilsBundle\Model\ModelUtil; | ||
use Twig\Environment; | ||
|
||
class ContactFormConfigElementType implements ListConfigElementTypeInterface | ||
{ | ||
const TYPE = 'contact_form'; | ||
|
||
public static $recipientEmail; | ||
/** | ||
* @var Environment | ||
*/ | ||
private $twig; | ||
/** | ||
* @var ModelUtil | ||
*/ | ||
private $modelUtil; | ||
|
||
public function __construct(ModelUtil $modelUtil, Environment $twig) | ||
{ | ||
$this->modelUtil = $modelUtil; | ||
$this->twig = $twig; | ||
} | ||
|
||
public function addToItemData(ItemInterface $item, ListConfigElementModel $configElement) | ||
{ | ||
// add email value to notification center tokens | ||
static::$recipientEmail = $item->getRawValue($configElement->emailField); | ||
$GLOBALS['TL_HOOKS']['formhybridBeforeCreateNotifications']['contao-list-bundle.addEmailToTokens'] = [static::class, 'addEmailToTokens']; | ||
|
||
// generate form | ||
$moduleId = $item->getModule()->id; | ||
|
||
$table = $item->getManager()->getFilterConfig()->getFilter()['dataContainer']; | ||
|
||
$identifier = $table.'_'.$moduleId.$item->getRawValue('id'); | ||
|
||
$item->setFormattedValue($configElement->templateVariable ?: 'contactForm', $this->twig->render('@HeimrichHannotContaoList/config_element/contact_form_modal_bootstrap4.html.twig', [ | ||
'identifier' => $identifier, | ||
'item' => $this, | ||
'form' => $this->generateSubmissionReader((int) $configElement->submissionReader), | ||
])); | ||
} | ||
|
||
public function addEmailToTokens(&$submissionData, $submission) | ||
{ | ||
$submissionData['form_value_contact_form_email'] = static::$recipientEmail; | ||
|
||
return true; | ||
} | ||
|
||
public function generateSubmissionReader(int $submissionReader) | ||
{ | ||
if (null === ($moduleModel = $this->modelUtil->findModelInstanceByPk('tl_module', $submissionReader))) { | ||
return ''; | ||
} | ||
|
||
$class = Module::findClass($moduleModel->type); | ||
|
||
if (!class_exists($class)) { | ||
return ''; | ||
} | ||
|
||
/** @var Module $module */ | ||
$module = new $class($moduleModel); | ||
|
||
return $module->generate(); | ||
} | ||
|
||
/** | ||
* Return the list config element type alias. | ||
* | ||
* @return string | ||
*/ | ||
public static function getType(): string | ||
{ | ||
return static::TYPE; | ||
} | ||
|
||
/** | ||
* Return the list config element type palette. | ||
* | ||
* @return string | ||
*/ | ||
public function getPalette(): string | ||
{ | ||
return '{config_legend},contactFormExplanation,submissionReader,emailField;'; | ||
} | ||
|
||
/** | ||
* Update the item data. | ||
* | ||
* @param ListConfigElementData $configElementData | ||
*/ | ||
public function addToListItemData(ListConfigElementData $configElementData): void | ||
{ | ||
$this->addToItemData($configElementData->getItem(), $configElementData->getListConfigElement()); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/Resources/views/config_element/contact_form_modal_bootstrap4.html.twig
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,23 @@ | ||
<div class="contact-form"> | ||
<!-- Button trigger modal --> | ||
<a href="#" data-toggle="modal" data-target="#contact_{{ identifier }}_modal"> | ||
{{ 'huh.list.misc.contact'|trans }} | ||
</a> | ||
|
||
<!-- Modal --> | ||
<div class="modal fade" id="contact_{{ identifier }}_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> | ||
<div class="modal-dialog modal-xl" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="exampleModalLabel">{{ 'huh.list.misc.contact'|trans }}</h5> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
{{ form|raw }} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |