Skip to content

Instantly share code, notes, and snippets.

@localhorst
Created February 11, 2021 11:19
Show Gist options
  • Save localhorst/f2015cbe7f66c715b29587c88a8ef27e to your computer and use it in GitHub Desktop.
Save localhorst/f2015cbe7f66c715b29587c88a8ef27e to your computer and use it in GitHub Desktop.
<?php
namespace Myself\MySitepackage\Hooks;
use TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface;
use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
/**
* @author Martin Terber <martin.terber@ppw.de>
*/
class FormHooks
{
/**
* @param \TYPO3\CMS\Form\Domain\Runtime\FormRuntime $formRuntime
* @param \TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface $renderable
* @return void
*/
public function beforeRendering(FormRuntime $formRuntime, RootRenderableInterface $renderable)
{
if ($renderable instanceof \TYPO3\CMS\Form\Domain\Model\FormDefinition) {
if (count($renderable->getPages()) > 1 ) {
$pages = $renderable->getPages();
$renderable->setRenderingOption("navigation", $pages);
}
}
}
}
@localhorst
Copy link
Author

localhorst commented Feb 11, 2021

Use it in your Form.html fluid template like that:
(navigation links to be added)

<ul class="form-navigation">
    <f:for each="{form.renderingOptions.navigation}" as="navItem" iteration="i">
        <li>
            <f:if condition="{navItem.index} < {form.currentPage.index}">
                <f:then>
                    <button formnovalidate="formnovalidate" type="submit"
                            name="tx_form_formframework[myformname-123][__currentPage]"
                            value="{navItem.index}">{i.cycle}. {navItem.label}
                    </button>
                </f:then>
                <f:else>
                    <span>{i.cycle}. {navItem.label}</span>
                </f:else>
            </f:if>
        </li>
    </f:for>
</ul>

@localhorst
Copy link
Author

localhorst commented Mar 19, 2021

In your ext_localconf.php:

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['beforeRendering'][1613033383] 
    = \Myself\MySitepackage\Hooks\FormHooks::class;

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