-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a front end module that displays the steps of a given form :)
- Loading branch information
Showing
9 changed files
with
182 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
/** | ||
* mp_forms extension for Contao Open Source CMS | ||
* | ||
* @copyright Copyright (c) 2015-2016, terminal42 gmbh | ||
* @author terminal42 gmbh <[email protected]> | ||
* @license http://opensource.org/licenses/lgpl-3.0.html LGPL | ||
* @link https://github.com/terminal42/contao-mp_forms | ||
*/ | ||
|
||
class MPFormsStepsModule extends \Module | ||
{ | ||
|
||
/** | ||
* Template | ||
* @var string | ||
*/ | ||
protected $strTemplate = 'mod_mp_forms_steps'; | ||
|
||
|
||
/** | ||
* Display a wildcard in the back end | ||
* | ||
* @return string | ||
*/ | ||
public function generate() | ||
{ | ||
if (TL_MODE == 'BE') { | ||
/** @var \BackendTemplate|object $objTemplate */ | ||
$objTemplate = new \BackendTemplate('be_wildcard'); | ||
|
||
$objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['mp_form_steps'][0]) . ' ###'; | ||
$objTemplate->title = $this->headline; | ||
$objTemplate->id = $this->id; | ||
$objTemplate->link = $this->name; | ||
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; | ||
|
||
return $objTemplate->parse(); | ||
} | ||
|
||
return parent::generate(); | ||
} | ||
|
||
|
||
/** | ||
* Generate the module | ||
*/ | ||
protected function compile() | ||
{ | ||
$navTpl = new \FrontendTemplate($this->navigationTpl ?: 'nav_default'); | ||
$navTpl->level = 0; | ||
$navTpl->items = $this->buildNavigationItems(); | ||
$this->Template->navigation = $navTpl->parse(); | ||
} | ||
|
||
/** | ||
* Builds the navigation array items. | ||
* | ||
* @return array | ||
*/ | ||
private function buildNavigationItems() | ||
{ | ||
$manager = new MPFormsFormManager($this->form); | ||
|
||
$steps = range(0, $manager->getNumberOfSteps() - 1); | ||
$items = []; | ||
$firstFailingStep = $manager->validateSteps(); | ||
|
||
foreach ($steps as $step) { | ||
|
||
// Check if step can be accessed | ||
$cantBeAccessed = true !== $firstFailingStep && $step > $firstFailingStep; | ||
|
||
// Only active if current step or step cannot be accessed because of | ||
// previous steps | ||
$isActive = $step === $manager->getCurrentStep() || $cantBeAccessed; | ||
|
||
$items[] = [ | ||
'isActive' => $isActive, | ||
'class' => 'step_' . $step . (($cantBeAccessed) ? ' forbidden' : ''), | ||
'href' => $manager->getUrlForStep($step), | ||
'title' => $manager->getLabelForStep($step), | ||
'link' => $manager->getLabelForStep($step), | ||
'nofollow' => true | ||
]; | ||
} | ||
|
||
\Haste\Generator\RowClass::withKey('class') | ||
->addFirstLast() | ||
->addEvenOdd() | ||
->applyTo($items); | ||
|
||
return $items; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* mp_forms extension for Contao Open Source CMS | ||
* | ||
* @copyright Copyright (c) 2015-2016, terminal42 gmbh | ||
* @author terminal42 gmbh <[email protected]> | ||
* @license http://opensource.org/licenses/lgpl-3.0.html LGPL | ||
* @link https://github.com/terminal42/contao-mp_forms | ||
*/ | ||
|
||
/** | ||
* Table tl_module | ||
*/ | ||
$GLOBALS['TL_DCA']['tl_module']['palettes']['mp_form_steps'] .= ' | ||
{title_legend},name,headline,type; | ||
{config_legend},form,navigationTpl; | ||
{template_legend:hide},customTpl; | ||
{protected_legend:hide},protected; | ||
{expert_legend:hide},guests,cssID,space'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
/** | ||
* mp_forms extension for Contao Open Source CMS | ||
* | ||
* @copyright Copyright (c) 2015-2016, terminal42 gmbh | ||
* @author terminal42 gmbh <[email protected]> | ||
* @license http://opensource.org/licenses/lgpl-3.0.html LGPL | ||
* @link https://github.com/terminal42/contao-mp_forms | ||
*/ | ||
|
||
/** | ||
* Front end modules | ||
*/ | ||
$GLOBALS['TL_LANG']['FMD']['mp_form_steps'] = ['MPForms - Schritte', 'Zeigt eine Navigation für die Schritte eines mehrseitigen Formulars an.']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
/** | ||
* mp_forms extension for Contao Open Source CMS | ||
* | ||
* @copyright Copyright (c) 2015-2016, terminal42 gmbh | ||
* @author terminal42 gmbh <[email protected]> | ||
* @license http://opensource.org/licenses/lgpl-3.0.html LGPL | ||
* @link https://github.com/terminal42/contao-mp_forms | ||
*/ | ||
|
||
/** | ||
* Front end modules | ||
*/ | ||
$GLOBALS['TL_LANG']['FMD']['mp_form_steps'] = ['MPForms - Steps', 'Displays a step navigation for a given multipage form.']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php $this->extend('block_unsearchable'); ?> | ||
|
||
<?php $this->block('content'); ?> | ||
|
||
<?= $this->navigation ?> | ||
|
||
<?php $this->endblock(); ?> |