Skip to content

Commit

Permalink
see cl 1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Patzer committed Sep 24, 2019
1 parent 937915c commit 0a8d41e
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.7.0] - 2019-09-24

#### Added
- contact form config element type

## [1.6.0] - 2019-09-13

#### Fixed
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -22,8 +22,9 @@
"require": {
"php": "^7.1",
"contao/core-bundle": "^4.4",
"heimrichhannot/contao-utils-bundle": "^2.1",
"heimrichhannot/contao-be_explanation-bundle": "^2.2",
"heimrichhannot/contao-filter-bundle": "^1.0-beta",
"heimrichhannot/contao-utils-bundle": "^2.1",
"heimrichhannot-contao-components/masonry": ">=4.2, <=4.3",
"heimrichhannot-contao-components/imagesloaded": "4.1.*",
"heimrichhannot-contao-components/jscroll": "2.3.*",
Expand Down
111 changes: 111 additions & 0 deletions src/ConfigElementType/ContactFormConfigElementType.php
@@ -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());
}
}
4 changes: 2 additions & 2 deletions src/DataContainer/ListConfigElementContainer.php
Expand Up @@ -40,7 +40,7 @@ public function __construct(ListConfigElementRegistry $configElementRegistry, Co
*
* @return array
*/
public function getConfigElementTypes(DC_Table $dcTable)
public function getConfigElementTypes(DC_Table $dc)
{
$types = array_keys($this->configElementRegistry->getConfigElementTypes());

Expand All @@ -58,7 +58,7 @@ public function getConfigElementTypes(DC_Table $dcTable)
return $types;
}

public function onLoadCallback($dcTable)
public function onLoadCallback($dc)
{
$configElementTypes = $this->configElementRegistry->getConfigElementTypes();

Expand Down
4 changes: 4 additions & 0 deletions src/Resources/config/services.yml
Expand Up @@ -101,5 +101,9 @@ services:

# List config element types
HeimrichHannot\ListBundle\ConfigElementType\ImageConfigElementType:
autowire: true
tags: ['huh.list.config_element_type']

HeimrichHannot\ListBundle\ConfigElementType\ContactFormConfigElementType:
autowire: true
tags: ['huh.list.config_element_type']
33 changes: 33 additions & 0 deletions src/Resources/contao/dca/tl_list_config_element.php
Expand Up @@ -188,5 +188,38 @@
'eval' => ['tl_class' => 'w50 autoheight', 'fieldType' => 'checkbox', 'filesOnly' => true, 'extensions' => Config::get('validImageTypes'), 'mandatory' => true, 'multiple' => true],
'sql' => "blob NULL",
],
'contactFormExplanation' => [
'inputType' => 'explanation',
'eval' => [
'text' => &$GLOBALS['TL_LANG']['tl_list_config_element']['contactFormExplanation'],
'class' => 'tl_info',
'tl_class' => 'long',
]
],
'submissionReader' => [
'label' => &$GLOBALS['TL_LANG']['tl_list_config_element']['submissionReader'],
'exclude' => true,
'filter' => true,
'inputType' => 'select',
'options' => [],
'reference' => &$GLOBALS['TL_LANG']['tl_']['reference'],
'options_callback' => function () {
return System::getContainer()->get('huh.utils.choice.model_instance')->getCachedChoices([
'dataContainer' => 'tl_module'
]);
},
'eval' => ['tl_class' => 'w50', 'mandatory' => true, 'includeBlankOption' => true, 'chosen' => true],
'sql' => "varchar(64) NOT NULL default ''"
],
'emailField' => [
'label' => &$GLOBALS['TL_LANG']['tl_list_config_element']['emailField'],
'inputType' => 'select',
'options_callback' => function (DataContainer $dc) {
return \HeimrichHannot\ListBundle\Util\ListConfigElementHelper::getFields($dc);
},
'exclude' => true,
'eval' => ['includeBlankOption' => true, 'mandatory' => true, 'chosen' => true, 'tl_class' => 'w50 autoheight'],
'sql' => "varchar(64) NOT NULL default ''",
],
],
];
8 changes: 7 additions & 1 deletion src/Resources/contao/languages/de/tl_list_config_element.php
Expand Up @@ -28,6 +28,11 @@
$lang['genderField'][1] = 'Wählen Sie hier das Feld aus, das das Geschlecht der Instanz enthält.';
$lang['placeholderImages'][0] = 'Platzhalterbilder';
$lang['placeholderImages'][1] = 'Wählen Sie hier Platzhalterbilder aus.';
$lang['submissionReader'][0] = 'Einsendungsleser';
$lang['submissionReader'][1] = 'Wählen Sie hier ein Modul vom Typ "Einsendungsleser" aus.';
$lang['emailField'][0] = 'E-Mail-Feld';
$lang['emailField'][1] = 'Wählen Sie hier das Feld aus, an das die E-Mail verschickt werden soll.';
$lang['contactFormExplanation'] = 'Die E-Mail-Adresse, an die das Formular verschickt wird, finden Sie im Notification-Center-Token ##form_value_contact_form_email##.';

/**
* Legends
Expand All @@ -41,9 +46,10 @@
*/
$lang['reference'] = [
\HeimrichHannot\ListBundle\ConfigElementType\ImageConfigElementType::TYPE => 'Bild',
\HeimrichHannot\ListBundle\ConfigElementType\ContactFormConfigElementType::TYPE => 'Kontaktformular',
\HeimrichHannot\ListBundle\Backend\ListConfigElement::PLACEHOLDER_IMAGE_MODE_SIMPLE => 'einfach',
\HeimrichHannot\ListBundle\Backend\ListConfigElement::PLACEHOLDER_IMAGE_MODE_GENDERED => 'geschlechtsspezifisch',
\HeimrichHannot\ListBundle\Backend\ListConfigElement::PLACEHOLDER_IMAGE_MODE_RANDOM => 'zufällig',
\HeimrichHannot\ListBundle\Backend\ListConfigElement::PLACEHOLDER_IMAGE_MODE_RANDOM => 'zufällig',
];

/**
Expand Down
1 change: 1 addition & 0 deletions src/Resources/translations/messages.de.yml
Expand Up @@ -4,6 +4,7 @@ huh.list.labels.ajaxPaginationNext: Mehr laden
# misc
huh.list.misc.detailsTitle: Details
huh.list.misc.shareTitle: Teilen
huh.list.misc.contact: Kontakt

# count items text
huh.list.count.text.default: '{0} Es wurden keine Einträge gefunden.|{1}Es wurde %count% Eintrag gefunden.|]1,Inf[ Es wurden %count% Einträge gefunden.'
Expand Down
@@ -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">&times;</span>
</button>
</div>
<div class="modal-body">
{{ form|raw }}
</div>
</div>
</div>
</div>
</div>

0 comments on commit 0a8d41e

Please sign in to comment.