Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add the MP Forms v5 support #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
"composer/semver": "^1.0 || ^2.0 || ^3.0",
"doctrine/dbal": "^2.11 || ^3.0",
"jean85/pretty-package-versions": "^1.0 || ^2.0",
"mvo/contao-group-widget": "^1.3"
"mvo/contao-group-widget": "^1.3",
"php-http/message-factory": "^1.1"
},
"require-dev": {
"contao/manager-plugin": "^2.0",
"friendsofphp/php-cs-fixer": "^3.0",
"terminal42/contao-leads": "^1.4",
"terminal42/contao-mp_forms": "^4.4"
"terminal42/contao-leads": "^3.0",
"terminal42/contao-mp_forms": "^5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -51,7 +52,8 @@
"config": {
"allow-plugins": {
"contao-components/installer": true,
"contao/manager-plugin": true
"contao/manager-plugin": true,
"php-http/discovery": true
}
}
}
13 changes: 8 additions & 5 deletions src/EventListener/FormHookListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@
use Contao\FormFieldModel;
use Contao\FrontendTemplate;
use Contao\StringUtil;
use Contao\System;
use Contao\Widget;
use InspiredMinds\ContaoFieldsetDuplication\Helper\FieldHelper;
use MPFormsFormManager;
use Symfony\Component\HttpFoundation\RequestStack;
use Terminal42\MultipageFormsBundle\FormManagerFactoryInterface;

class FormHookListener
{
public const TABLE_FIELD = 'fieldset_duplicates';

protected $requestStack;
protected $fieldHelper;
protected $formManagerFactory;

public function __construct(RequestStack $requestStack, FieldHelper $fieldHelper)
public function __construct(RequestStack $requestStack, FieldHelper $fieldHelper, FormManagerFactoryInterface $formManagerFactory = null)
{
$this->requestStack = $requestStack;
$this->fieldHelper = $fieldHelper;
$this->formManagerFactory = $formManagerFactory;
}

public function onLoadFormField(Widget $widget, string $formId, array $data, Form $form): Widget
Expand Down Expand Up @@ -75,9 +78,9 @@ public function onCompileFormFields(array $fields, $formId, Form $objForm): arra
}

// Get the submitted data from MPForms
if (count($submittedData) === 0 && class_exists(\MPFormsFormManager::class)) {
$manager = new MPFormsFormManager($objForm->id);
$submittedData = $manager->getDataOfStep($manager->getCurrentStep())['originalPostData'] ?? [];
if (count($submittedData) === 0 && $this->formManagerFactory !== null) {
$manager = $this->formManagerFactory->forFormId((int) $objForm->id);
$submittedData = $manager->getDataOfStep($manager->getCurrentStep())->getOriginalPostData()->all();
}

// check if form was submitted
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
arguments:
- '@request_stack'
- '@inspiredminds.fieldsetduplication.helper.field'
- '@?Terminal42\MultipageFormsBundle\FormManagerFactoryInterface'
tags:
- { name: contao.hook, hook: loadFormField, method: onLoadFormField }
- { name: contao.hook, hook: compileFormFields, method: onCompileFormFields, priority: -100}
Expand Down