Giter Club home page Giter Club logo

form-custom-templates's Introduction

B13 - Form Custom templates

Allows a user to define the email template for each email finisher and override it in the plugin settings.

The global defined template is used by default. Additional templates need to be configured!

Install

composer req b13/form-custom-templates

Configuration

Doktype and typeNum

In case the doktype (default: 125) or typeNum (default: 101) are already used in the current TYPO3 instance both values can be changed in Settings -> Extension Configuration. The constants plugin.tx_form_custom_templates.doktype and plugin.tx_form_custom_templates.typeNum are set automatically depending on the set values in the Extension Configuration.

Add TypoScript configuration

Use @import or include_static_file to add the basic configuration.

@import 'EXT:form_custom_templates/Configuration/TypoScript/setup.typoscript'

This will extend the EmailToSender and EmailToReceiver finisher with a template selector. The template selector will list all pages of doktype Email (plugin.tx_form_custom_templates.doktype default: 125). By default, the page doktype Email uses a template based on SystemEmail.html

Custom html templates:

[page["doktype"] == {$plugin.tx_form_custom_templates.doktype}]
    # Set the template
    page.10.templateName = SystemEmailTemplate

    # Use custom template paths
    page.10.templateRootPaths.20 = EXT:SITE_PACKAGE/Resources/Private/Frontend/Templates/
    page.10.partialRootPaths.20 = EXT:SITE_PACKAGE/Resources/Private/Frontend/Partials/
    page.10.layoutRootPaths.20 = EXT:SITE_PACKAGE/Resources/Private/Frontend/Layouts/
[END]

Custom result list template:

Define file path (omit suffix). A Template in html and txt format is required.

plugin.tx_form_custom_templates.resultList.templatePath = EXT:form_custom_templates/Resources/Private/Frontend/Partials/ResultTable

Define default template

module.tx_form.settings.yamlConfigurations.555 = EXT:YOUR_SITE_PACKAGE/Configuration/Yaml/CustomTemplate.yaml
plugin.tx_form.settings.yamlConfigurations.555 = EXT:YOUR_SITE_PACKAGE/Configuration/Yaml/CustomTemplate.yaml
TYPO3:
  CMS:
    Form:
      prototypes:
        standard:
          finishersDefinition:
            EmailToSender:
              formEditor:
                predefinedDefaults:
                  options:
                    emailTemplateUid: '221'

form-custom-templates's People

Contributors

achimfritz avatar davidsteeb avatar ervaude avatar ochorocho avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

galinei

form-custom-templates's Issues

Optimize plaintext rendering

At the moment html2text is used to generate the plaintext email content.
The problem is, it does not give control over the rendering.

Render a additional txt format.

Todos ...

  • Add icons v10
  • Fix styling select box in v10

Prefill variables

Some variables are not prefilled.
Variables need to be filled to allow basic styling/config like logo highlight color and such.

  • {typo3.systemConfiguration.backend.loginLogo}
  • {typo3.systemConfiguration.backend.loginHighlightColor}

Configurable field identifier

Field identifier can't be changed. But this is important in case a email template is used for multiple forms.

Allow to change e.g. {text-1} to {firstname}.

Add PSR-14 EventListener in Services.yaml to replace DataStructureEmailOptionsHook with FlexFormParsingModifyEventListener in v12

If you overwrite the Plugin Flexform settings you get a warning and empty templates. The hook to add the Pages as options for templates is no longer available in v12, therefore it has to be replaced by the PSR-14 EventListener.

In Configuration/Services.yaml add

   B13\FormCustomTemplates\EventListener\FlexFormParsingModifyEventListener:
      tags:
        - name: event.listener
          identifier: 'form-custom-templates/modify-data-structure'
          method: 'modifyDataStructure'

Create new file in Classes\EventListeners\FlexFormParsingModifyEventListener.php and add

<?php
declare(strict_types=1);
namespace B13\FormCustomTemplates\EventListener;

use TYPO3\CMS\Core\Configuration\Event\AfterFlexFormDataStructureParsedEvent;
use B13\FormCustomTemplates\Service\EmailTemplateService;

final class FlexFormParsingModifyEventListener
{
    public function modifyDataStructure(AfterFlexFormDataStructureParsedEvent $event): void
    {
        $identifier = $event->getIdentifier();
        if (($identifier['ext-form-overrideFinishers'] ?? '') === 'enabled') {
            $parsedDataStructure = $event->getDataStructure();
            foreach ($parsedDataStructure['sheets'] as $sheetIdentifier => $sheet) {
                $addToFinishers = ['EmailToSender', 'EmailToReceiver'];
                foreach ($addToFinishers as $finisherIdentifier) {
                    if ($parsedDataStructure['sheets'][$sheetIdentifier]['ROOT']['el']['settings.finishers.' . $finisherIdentifier . '.emailTemplateUid'] ?? false) {
                        //The array has to be an associative array with label and value to be rendered correctly
                        //I don't change the initial function, because I don't know if it breaks anything else.
                        //should be changed or an additional function/utility should be added...(@ToDo)
                        $assocOptions = [];
                        $oldOptions = $parsedDataStructure['sheets'][$sheetIdentifier]['ROOT']['el']['settings.finishers.' . $finisherIdentifier . '.emailTemplateUid']['config']['items'];
                        foreach($oldOptions as $index => $option) {
                            $assocOptions[$index]['label'] = $option[0];
                            $assocOptions[$index]['value'] = $option[1];
                        }
                        $options = EmailTemplateService::getOptions();
                        $indexCounter = count($oldOptions);
                        foreach($options as $index => $option) {
                            $indexCounter++;
                            $assocOptions[$indexCounter]['label'] = $option[0];
                            $assocOptions[$indexCounter]['value'] = $option[1];
                        }
                        $parsedDataStructure['sheets'][$sheetIdentifier]['ROOT']['el']['settings.finishers.' . $finisherIdentifier . '.emailTemplateUid']['config']['items'] = $assocOptions;
                    }
                }
            }
            $event->setDataStructure($parsedDataStructure);
        }
    }
}

Now the dropdown in the flexform is filled correctly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.