Skip to content

Commit 459050e

Browse files
authored
Merge pull request #5 from studio24/feature/custom-html-block
Added custom HTML block for raw HTML or view insertions into form.
2 parents 5683c1e + 3fca0c1 commit 459050e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/FieldTypes/Html.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Studio24\AccessibleForms\FieldTypes;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Symfony\Component\Form\FormInterface;
7+
use Symfony\Component\Form\FormView;
8+
use Symfony\Component\OptionsResolver\OptionsResolver;
9+
use Twig\Markup;
10+
11+
class Html extends AbstractType
12+
{
13+
public function configureOptions(OptionsResolver $resolver)
14+
{
15+
$resolver->setDefaults([
16+
'html' => null,
17+
'view' => null
18+
]);
19+
}
20+
21+
public function buildView(FormView $view, FormInterface $form, array $options)
22+
{
23+
$view->vars['html'] = $options['html'];
24+
25+
// Load in template as Twig\Markup object.
26+
if (!empty($options['view'])) {
27+
$view->vars['html'] = new Markup($options['view'], 'UTF-8');
28+
}
29+
}
30+
}

src/Resources/views/Form/accessible-forms.html.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,9 @@
221221
{{ block('attributes') }}
222222
{%- endblock widget_attributes -%}
223223

224+
{# Custom HTML block #}
225+
{%- block html_row -%}
226+
{{ html }}
227+
{%- endblock -%}
228+
229+

0 commit comments

Comments
 (0)