Skip to content

Commit

Permalink
Add non-form element text with link (#54)
Browse files Browse the repository at this point in the history
Co-authored-by: Wouter Thys <[email protected]>
  • Loading branch information
CaprinaeWT and Wouter Thys authored Feb 13, 2023
1 parent d386890 commit 1286ec0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Controller/FormBuilderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
26 changes: 26 additions & 0 deletions Resources/public/BootstrapFormBuilder/assets/js/data/other.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Text input-->
<div class="form-group">
<div class="col-md-4">
&nbsp;
</div>
<div class="col-md-8">
<strong><p>{{ textbeforelink }} <a href="{{ url }}">{{ cta }}</a> {{ textafterlink }}</p></strong>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,6 +57,7 @@ define(function(require) {
captcha : captcha,
privacycheckbox : privacycheckbox,
title : title,
filebutton : filebutton
filebutton : filebutton,
linktext : linktext,
}
});
12 changes: 12 additions & 0 deletions Resources/views/Block/block_form_builder.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@
</div>
{% endmacro %}

{% macro showTextLinkField(elem) %}
<div class="form-group mb-4">
<div class="form-group mb-4">
<p class="font-weight-bold">
{{ elem.fields.textbeforelink.value }} <a href="{{ elem.fields.url.value }}">{{ elem.fields.cta.value }}</a> {{ elem.fields.textafterlink.value }}
</p>
</div>
</div>
{% 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 %}
Expand Down

0 comments on commit 1286ec0

Please sign in to comment.