Skip to content

Commit

Permalink
Merge pull request #79 from ker0x/feature/issue-75
Browse files Browse the repository at this point in the history
Add support for Bootstrap 5
  • Loading branch information
maxhelias authored Jun 28, 2021
2 parents 8db439f + 06ca603 commit 0b71d42
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Note that if you're putting the `phone_number` type on an already-existing schem

### Twig Templating

If any of the `form_div_layout`, `bootstrap_3_*` or `bootstrap_4_*` layouts are registered in your twig configuration, the bundle will automatically register the template used to render the `Misd\PhoneNumberBundle\Form\Type` form type.
If any of the `form_div_layout`, `bootstrap_3_*`, `bootstrap_4_*` or `bootstrap_5_*` layouts are registered in your twig configuration, the bundle will automatically register the template used to render the `Misd\PhoneNumberBundle\Form\Type` form type.
#### phone_number_format

The `phone_number_format` filter can be used to format a phone number object. A `libphonenumber\PhoneNumberFormat` constant can be passed as argument to specify in which format the number should be printed.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"require": {
"php": ">7.2.5",
"giggsey/libphonenumber-for-php": "^8.0",
"symfony/framework-bundle": "^3.4|^4.3|^5.0"
"symfony/framework-bundle": "^3.4|^4.3|^5.0",
"symfony/intl": "^3.4|^4.3|^5.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.12|^2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class FormTwigTemplateCompilerPass implements CompilerPassInterface
private $phoneNumberLayout = '@MisdPhoneNumber/Form/phone_number.html.twig';
private $phoneNumberBootstrapLayout = '@MisdPhoneNumber/Form/phone_number_bootstrap.html.twig';
private $phoneNumberBootstrap4Layout = '@MisdPhoneNumber/Form/phone_number_bootstrap_4.html.twig';
private $phoneNumberBootstrap5Layout = '@MisdPhoneNumber/Form/phone_number_bootstrap_5.html.twig';

/**
* {@inheritdoc}
Expand All @@ -39,7 +40,11 @@ public function process(ContainerBuilder $container)
}

// Insert right after base template if it exists.
if (false !== ($key = array_search('bootstrap_4_horizontal_layout.html.twig', $parameter))) {
if (false !== ($key = array_search('bootstrap_5_horizontal_layout.html.twig', $parameter))) {
array_splice($parameter, ++$key, 0, [$this->phoneNumberBootstrap5Layout]);
} elseif (false !== ($key = array_search('bootstrap_5_layout.html.twig', $parameter))) {
array_splice($parameter, ++$key, 0, [$this->phoneNumberBootstrap5Layout]);
} elseif (false !== ($key = array_search('bootstrap_4_horizontal_layout.html.twig', $parameter))) {
array_splice($parameter, ++$key, 0, [$this->phoneNumberBootstrap4Layout]);
} elseif (false !== ($key = array_search('bootstrap_4_layout.html.twig', $parameter))) {
array_splice($parameter, ++$key, 0, [$this->phoneNumberBootstrap4Layout]);
Expand Down
11 changes: 11 additions & 0 deletions src/Resources/views/Form/phone_number_bootstrap_5.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% block phone_number_widget -%}
{% if widget is constant('Misd\\PhoneNumberBundle\\Form\\Type\\PhoneNumberType::WIDGET_COUNTRY_CHOICE') %}
{% set attr = attr|merge({class: (attr.class|default('') ~ ' input-group')|trim}) %}
<div {{ block('widget_container_attributes') }}>
{{- form_widget(form.country) -}}
{{- form_widget(form.number) -}}
</div>
{% else -%}
{{- block('form_widget_simple') -}}
{%- endif %}
{%- endblock phone_number_widget %}

0 comments on commit 0b71d42

Please sign in to comment.