From 1286ec0ad7992037035d9fa813aed16bab22e7e4 Mon Sep 17 00:00:00 2001 From: CaprinaeWT <93272674+CaprinaeWT@users.noreply.github.com> Date: Mon, 13 Feb 2023 14:42:36 +0100 Subject: [PATCH] Add non-form element text with link (#54) Co-authored-by: Wouter Thys --- Controller/FormBuilderController.php | 2 +- .../assets/js/data/other.json | 26 +++++++++++++++++++ .../assets/js/templates/snippet/linktext.html | 9 +++++++ .../js/templates/snippet/snippet-templates.js | 6 +++-- .../views/Block/block_form_builder.html.twig | 12 +++++++++ 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 Resources/public/BootstrapFormBuilder/assets/js/templates/snippet/linktext.html diff --git a/Controller/FormBuilderController.php b/Controller/FormBuilderController.php index fa65723..bc46824 100644 --- a/Controller/FormBuilderController.php +++ b/Controller/FormBuilderController.php @@ -269,7 +269,7 @@ public function generateFormFromFormBuilder($formbuild): array } } - if ($elem->typefield === 'title') { + if ($elem->typefield === 'title' || $elem->typefield === 'linktext') { $next_orphan_html_elem = $elem; } } diff --git a/Resources/public/BootstrapFormBuilder/assets/js/data/other.json b/Resources/public/BootstrapFormBuilder/assets/js/data/other.json index 5394ab8..4baa8dc 100644 --- a/Resources/public/BootstrapFormBuilder/assets/js/data/other.json +++ b/Resources/public/BootstrapFormBuilder/assets/js/data/other.json @@ -45,5 +45,31 @@ }, "title": "Title", "typefield": "title" + }, + { + "title": "Link text", + "typefield":"linktext", + "fields": { + "textbeforelink": { + "label": "Text before link", + "type": "textarea", + "value": "Visit" + }, + "cta": { + "label": "Link text", + "type": "input", + "value": "google" + }, + "url": { + "label": "Link URL", + "type": "input", + "value": "https://www.google.com/" + }, + "textafterlink": { + "label": "Text after link", + "type": "textarea", + "value": "for more info" + } + } } ] \ No newline at end of file diff --git a/Resources/public/BootstrapFormBuilder/assets/js/templates/snippet/linktext.html b/Resources/public/BootstrapFormBuilder/assets/js/templates/snippet/linktext.html new file mode 100644 index 0000000..a1cc0ff --- /dev/null +++ b/Resources/public/BootstrapFormBuilder/assets/js/templates/snippet/linktext.html @@ -0,0 +1,9 @@ + +
+
+   +
+
+

{{ textbeforelink }} {{ cta }} {{ textafterlink }}

+
+
diff --git a/Resources/public/BootstrapFormBuilder/assets/js/templates/snippet/snippet-templates.js b/Resources/public/BootstrapFormBuilder/assets/js/templates/snippet/snippet-templates.js index 6acab86..551f50e 100755 --- a/Resources/public/BootstrapFormBuilder/assets/js/templates/snippet/snippet-templates.js +++ b/Resources/public/BootstrapFormBuilder/assets/js/templates/snippet/snippet-templates.js @@ -26,7 +26,8 @@ define(function(require) { captcha = require('text!templates/snippet/captcha.html'), privacycheckbox = require('text!templates/snippet/privacycheckbox.html'), title = require('text!templates/snippet/title.html'), - filebutton = require('text!templates/snippet/filebutton.html'); + filebutton = require('text!templates/snippet/filebutton.html'), + linktext = require('text!templates/snippet/linktext.html'); return { formname : formname, @@ -56,6 +57,7 @@ define(function(require) { captcha : captcha, privacycheckbox : privacycheckbox, title : title, - filebutton : filebutton + filebutton : filebutton, + linktext : linktext, } }); \ No newline at end of file diff --git a/Resources/views/Block/block_form_builder.html.twig b/Resources/views/Block/block_form_builder.html.twig index c75dc8d..9f0eda8 100644 --- a/Resources/views/Block/block_form_builder.html.twig +++ b/Resources/views/Block/block_form_builder.html.twig @@ -17,12 +17,24 @@ {% endmacro %} +{% macro showTextLinkField(elem) %} +
+
+

+ {{ elem.fields.textbeforelink.value }} {{ elem.fields.cta.value }} {{ elem.fields.textafterlink.value }} +

+
+
+{% endmacro %} {% macro handleExtraHtml(html_prefix_col, form) %} {% if html_prefix_col[form.vars.name] is defined %} {% for elem in html_prefix_col[form.vars.name] %} {% if elem.typefield == 'title'%} {{ _self.showTitleField(elem) }} {% endif %} + {% if elem.typefield == 'linktext'%} + {{ _self.showTextLinkField(elem) }} + {% endif %} {% endfor %} {% endif %} {% endmacro %}