Skip to content

Commit

Permalink
[CIVIC-1493] Added webform related fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
govindmaloo committed Dec 13, 2023
1 parent e3b7127 commit a1cf1e6
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
.ct-webform {
$root: &;

.form-checkboxes,
.form-radios {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;

.ct-form-element {
margin-bottom: 0;
display: flex;
}
}

@include ct-component-theme($root) using($root, $theme) {
&#{$root}--with-background {
@include ct-component-property($root, $theme, background-color);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
{#
/**
* @file
* CivicTheme implementation to display a 'submit' form element.
*
* Variables:
* - value: [string] value.
* - attributes: [string] Additional attributes.
* - modifier_class: [string] Additional classes.
*/
#}

{% if 'secondary' in modifier_class %}
{% set type = 'secondary' %}
{% set type = 'secondary' %}
{% else %}
{% set type = 'primary' %}
{% set type = 'primary' %}
{% endif %}
{% set children %}
{% include "@atoms/button/button.twig" with {
{% include "@atoms/button/button.twig" with {
type: type,
text: attributes.value,
text: value,
modifier_class: modifier_class,
attributes: attributes,
kind: 'submit'
Expand All @@ -16,3 +28,4 @@
type: 'submit',
children: children,
} only %}

7 changes: 7 additions & 0 deletions web/themes/contrib/civictheme/includes/form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ function civictheme_preprocess_input(array &$variables): void {
if (isset($variables['attributes']['#civictheme_theme'])) {
unset($variables['attributes']['#civictheme_theme']);
}

// Fix htmlentity in submit button text.
$element = $variables['element'];

if (isset($element['#type']) && $element['#type'] == 'submit' && !empty($variables['attributes']['value'])) {
$variables['value'] = $variables['attributes']['value'];
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'block',
'block-' ~ configuration.provider|clean_class,
'block-' ~ plugin_id|clean_class,
modifier_class ? modifier_class : '',
] %}
<div{{ attributes.addClass(classes) }}>
{{ title_prefix }}
Expand Down
31 changes: 31 additions & 0 deletions web/themes/contrib/civictheme/templates/form/container.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{#
/**
* @file
* Default theme implementation of a container used to wrap child elements.
*
* Used for grouped form items. Can also be used as a theme wrapper for any
* renderable element, to surround it with a <div> and HTML attributes.
* See \Drupal\Core\Render\Element\RenderElement for more
* information on the #theme_wrappers render array property, and
* \Drupal\Core\Render\Element\container for usage of the container render
* element.
*
* Available variables:
* - attributes: HTML attributes for the containing element.
* - children: The rendered child elements of the container.
* - has_parent: A flag to indicate that the container has one or more parent
containers.
*
* @see template_preprocess_container()
*
* @ingroup themeable
*/
#}
{% set classes = [
has_parent ? 'js-form-wrapper form-wrapper',
modifier_class ? modifier_class,
'ct-contianer',
] %}
<div {{ attributes.addClass(classes) }}>
{{ children }}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{#
/**
* @file
* CivicTheme theme implementation to display a fieldset.
*/
#}
{% include '@atoms/fieldset/fieldset.twig' %}

Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@
/**
* @file
* CivicTheme implementation to display a 'submit' form element.
*
* Variables:
* - value: [string] value.
* - attributes: [string] Additional attributes.
* - modifier_class: [string] Additional classes.
*/
#}

{% if 'secondary' in modifier_class %}
{% set type = 'secondary' %}
{% set type = 'secondary' %}
{% else %}
{% set type = 'primary' %}
{% set type = 'primary' %}
{% endif %}
{% set children %}
{% include "@atoms/button/button.twig" with {
{% include "@atoms/button/button.twig" with {
type: type,
text: attributes.value,
text: value,
modifier_class: modifier_class,
attributes: attributes,
kind: 'submit',
theme: theme
kind: 'submit'
} only %}
{% endset %}
{% include "@molecules/form-element/form-element.twig" with {
type: 'submit',
children: children,
} only %}

19 changes: 19 additions & 0 deletions web/themes/contrib/civictheme/templates/webform/webform.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{#
/**
* @file
* Webform component.
*
* Variables:
* - attributes: [string] Additional attributes.
* - modifier_class: [string] Additional classes.
*/
#}

{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set modifier_class = '%s %s'|format(theme_class, modifier_class) %}

<form class="ct-webform {{ modifier_class }}" {{ attributes }}>
{{ title_prefix }}
{{ children }}
{{ title_suffix }}
</form>

0 comments on commit a1cf1e6

Please sign in to comment.