Skip to content

Instantly share code, notes, and snippets.

@xperseguers
Last active May 19, 2020 15:41
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xperseguers/5dfe069246f2aa0e7c7e418b5cccf200 to your computer and use it in GitHub Desktop.
Save xperseguers/5dfe069246f2aa0e7c7e418b5cccf200 to your computer and use it in GitHub Desktop.
Custom finisher for EXT:form in TYPO3 v8

Custom finisher

This gist is about creating your own custom finisher available for forms you create with EXT:form in TYPO3 v8.

Standard finishers let you send an email, redirect to a page, etc. This is about creating your own business logic when sending the form.

# File EXT:your_ext/Configuration/Yaml/MyCustomActionBackend.yaml
TYPO3:
CMS:
Form:
prototypes:
# add our finisher to the 'standard' form prototype
standard:
formElementsDefinition:
Form:
formEditor:
editors:
# 900 = 'finishers' in EXT:form/Configuration/Yaml/FormEditorSetup.yaml
900:
selectOptions:
# add the MyCustomAction finisher to the finishers select list
# "500" is to prevent overriding standard finishers which are < 100
500:
value: 'MyCustomAction'
label: 'My Custom Action'
propertyCollections:
finishers:
# add the MyCustomAction finisher editor configurations
# at the moment there are no editors but this is needed anyway to "see" the
# finisher added to the form and being able to remove it with the delete icon
# "500" below has nothing to do with the "500" above but I find it more logical
# to use same index :)
500:
__inheritances:
10: 'TYPO3.CMS.Form.mixins.FormEngineCustomActionMixin'
identifier: 'MyCustomAction'
editors:
__inheritances:
10: 'TYPO3.CMS.Form.mixins.formElementMixins.BaseCollectionEditorsMixin'
100:
label: 'My Custom Action'
200:
identifier: 'yourCustomOption'
templateName: 'Inspector-TextEditor'
label: 'Your custom option'
propertyPath: 'options.yourCustomOption'
enableFormelementSelectionButton: true
propertyValidators:
10: 'NotEmpty'
20: 'FormElementIdentifierWithinCurlyBracesInclusive'
finishersDefinition:
MyCustomAction:
formEditor:
iconIdentifier: 't3-form-icon-finisher'
predefinedDefaults:
options:
yourCustomOption: ''
mixins:
FormEngineCustomActionMixin:
elements:
yourCustomOption:
config:
type: 'input'
<?php
declare(strict_types=1);
// File EXT:your_ext/Classes/Domain/Finishers/MyCustomActionFinisher.php
namespace VENDOR\YourExt\Domain\Finishers;
use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException;
class MyCustomActionFinisher extends \TYPO3\CMS\Form\Domain\Finishers\EmailFinisher
{
/**
* Executes this finisher
* @see AbstractFinisher::execute()
*
* @throws FinisherException
*/
protected function executeInternal()
{
// TODO
parent::executeInternal();
}
}
# File EXT:your_ext/Configuration/Yaml/MyCustomActionFrontend.yaml
TYPO3:
CMS:
Form:
prototypes:
# add our finisher to the 'standard' form prototype
standard:
finishersDefinition:
MyCustomAction:
implementationClassName: 'VENDOR\YourExt\Domain\Finishers\MyCustomActionFinisher'
options:
#yourCustomOption: ''
# File EXT:your_ext/Configuration/TypoScript/setup.t3s
# or any other TypoScript file you use in your page tree
# Registration for the backend
module.tx_form {
settings {
yamlConfigurations {
100 = EXT:your_ext/Configuration/Yaml/MyCustomActionBackend.yaml
}
}
}
# Registration for the frontend
plugin.tx_form {
settings {
yamlConfigurations {
100 = EXT:your_ext/Configuration/Yaml/MyCustomActionFrontend.yaml
}
}
}
@gromerop
Copy link

In order to get the value of your custom option in frontend, you can uncoment the line 12 of MyCustomActionFrontend.yaml and replace it by yourCustomOption: '{yourCustomOption}'

# File EXT:your_ext/Configuration/Yaml/MyCustomActionFrontend.yaml
TYPO3:
  CMS:
    Form:
      prototypes:
          # add our finisher to the 'standard' form prototype
          standard:
            finishersDefinition:
              MyCustomAction:
                implementationClassName: 'VENDOR\YourExt\Domain\Finishers\MyCustomActionFinisher'
                options:
                  yourCustomOption: '{yourCustomOption}'

@totocrenn
Copy link

Is it still compatible with Typo3 V8.7.19 ? Maybe I'm doing something wrong but I can't manage to make it work in my typo3 instance

@benabbottnz
Copy link

Why are you trying to call the parent abstract method? This doesn't make any sense.

https://gist.github.com/xperseguers/5dfe069246f2aa0e7c7e418b5cccf200#file-mycustomactionfinisher-php-L21

@GhanshyamBhava
Copy link

GhanshyamBhava commented Aug 1, 2019

I have TYPO3 9.x setup, I followed the same steps for my custom finisher. But, while I debug the form values in the finisher It does not show.

$formData = $this->finisherContext->getFormValues();

Can you please help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment