|
| 1 | +## Funnel Layer |
| 2 | +A Funnel Layer is basically the same as an output workflow you already know. |
| 3 | +The big difference: It's a real frontend page with different actions, triggered by the user itself. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +### Dynamic Layout Layer |
| 8 | +By default, there is only one layer, a so-called "_Dynamic Layout Layer_". |
| 9 | + |
| 10 | +This layer is configured as `dynamicFunnelActionAware`, which means: |
| 11 | +- that you need to define you're own actions (See next chapter) |
| 12 | +- that you need to place them in your snippet template |
| 13 | + |
| 14 | +So, go ahead, create a snippet and drag it into the "Layout" field. |
| 15 | + |
| 16 | +Next, we need to configure some [funnel actions](./20_FunnelActions.md). |
| 17 | + |
| 18 | +*** |
| 19 | + |
| 20 | +### Custom Funnel Layer |
| 21 | +It is very easy to configure a custom funnel layer. |
| 22 | + |
| 23 | +#### Configuration |
| 24 | +```yaml |
| 25 | +services: |
| 26 | + App\Funnel\DummyLayer: |
| 27 | + tags: |
| 28 | + - { name: form_builder.output_workflow.funnel_layer, type: dummyLayer } |
| 29 | +``` |
| 30 | +
|
| 31 | +#### PHP Service |
| 32 | +```php |
| 33 | +<?php |
| 34 | + |
| 35 | +namespace App\Funnel; |
| 36 | + |
| 37 | +use FormBuilderBundle\Model\FunnelActionDefinition; |
| 38 | +use FormBuilderBundle\OutputWorkflow\Channel\Funnel\Layer\FunnelLayerData; |
| 39 | +use FormBuilderBundle\OutputWorkflow\Channel\Funnel\Layer\FunnelLayerInterface; |
| 40 | +use Symfony\Component\Form\Extension\Core\Type\TextType; |
| 41 | +use Symfony\Component\Form\FormBuilderInterface; |
| 42 | + |
| 43 | +class DummyLayer implements FunnelLayerInterface |
| 44 | +{ |
| 45 | + public function getName(): string |
| 46 | + { |
| 47 | + return 'Dummy Layer'; |
| 48 | + } |
| 49 | + |
| 50 | + public function getFormType(): array |
| 51 | + { |
| 52 | + /** |
| 53 | + * If you want to configure additional fields in backend, add them here |
| 54 | + */ |
| 55 | + |
| 56 | + return [ |
| 57 | + 'type' => TextType::class, |
| 58 | + 'options' => [] |
| 59 | + ]; |
| 60 | + } |
| 61 | + |
| 62 | + public function dynamicFunnelActionAware(): bool |
| 63 | + { |
| 64 | + /** |
| 65 | + * If you're returning true, |
| 66 | + * user is allowed to define its own funnel actions, |
| 67 | + * and you should return an empty array in the method below: getFunnelActionDefinitions() |
| 68 | + */ |
| 69 | + |
| 70 | + return false; |
| 71 | + } |
| 72 | + |
| 73 | + public function getFunnelActionDefinitions(): array |
| 74 | + { |
| 75 | + /** |
| 76 | + * If you want to define some predefined actions, |
| 77 | + * dynamicFunnelActionAware() needs to return false. |
| 78 | + * Then you're able to add them in your funnel layer layout (see template below) |
| 79 | + */ |
| 80 | + |
| 81 | + return [ |
| 82 | + new FunnelActionDefinition('dummyButton', 'Top Button') |
| 83 | + ]; |
| 84 | + } |
| 85 | + |
| 86 | + |
| 87 | + public function buildForm(FunnelLayerData $funnelLayerData, FormBuilderInterface $formBuilder): void |
| 88 | + { |
| 89 | + /** |
| 90 | + * If you need additional information from a given user, |
| 91 | + * just add some additional fields to the Layer form type. |
| 92 | + * You're also able to fetch this submitted data in upcoming channels |
| 93 | + * via SubmissionEvent->getFunnelRuntimeData() |
| 94 | + */ |
| 95 | + |
| 96 | + $formBuilder->add('consent', CheckboxType::class, ['constraints' => [new IsTrue()]]); |
| 97 | + } |
| 98 | + |
| 99 | + public function handleFormData(FunnelLayerData $funnelLayerData, array $formData): array |
| 100 | + { |
| 101 | + return $formData; |
| 102 | + } |
| 103 | + |
| 104 | + public function buildView(FunnelLayerData $funnelLayerData): void |
| 105 | + { |
| 106 | + $funnelLayerConfiguration = $funnelLayerData->getFunnelLayerConfiguration(); |
| 107 | + |
| 108 | + $viewArguments = [ |
| 109 | + 'dummyField' => $funnelLayerConfiguration['dummyField'] |
| 110 | + ]; |
| 111 | + |
| 112 | + $funnelLayerData->setFunnelLayerView('/funnel/dummy_layer.html.twig'); |
| 113 | + $funnelLayerData->setFunnelLayerViewArguments($viewArguments); |
| 114 | + } |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +#### JS Service |
| 119 | +```javascript |
| 120 | +pimcore.registerNS('Formbuilder.extjs.formPanel.outputWorkflow.funnelLayer.dummyLayer'); |
| 121 | +Formbuilder.extjs.formPanel.outputWorkflow.funnelLayer.dummyLayer = Class.create(Formbuilder.extjs.formPanel.outputWorkflow.funnelLayer.abstractLayer, { |
| 122 | + |
| 123 | + getConfigItems: function () { |
| 124 | + return [ |
| 125 | + { |
| 126 | + xtype:'textfield', |
| 127 | + name: 'dummyField', |
| 128 | + fieldLabel: 'My Dummy Field' |
| 129 | + } |
| 130 | + ]; |
| 131 | + } |
| 132 | +}); |
| 133 | +``` |
| 134 | + |
| 135 | +#### Twig Partial |
| 136 | +```twig |
| 137 | +{% if formTheme is not null %} |
| 138 | + {% form_theme form with (formTheme ~ '.html.twig') only %} |
| 139 | +{% endif %} |
| 140 | +
|
| 141 | +{% block funnel_content %} |
| 142 | +
|
| 143 | + {{ dump(dummyField) }} |
| 144 | + |
| 145 | + <div class="row"> |
| 146 | + {{ form_widget(form.consent) }} |
| 147 | + </div> |
| 148 | + |
| 149 | + {% if funnelActions.hasByName('dummyButton') %} |
| 150 | + {{ form_widget(form.dummyButton, {attr: {class: 'btn-primary'}, label: 'Do something' }) }} |
| 151 | + {% endif %} |
| 152 | +
|
| 153 | +{% endblock funnel_content %} |
| 154 | +``` |
0 commit comments