Skip to content

Commit

Permalink
add merge reqursively twig extension with last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Dec 18, 2019
1 parent 466a667 commit f765ed4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% include '@SyliusShop/Common/Form/_login.html.twig' with {'form': form.customer} %}
{% endif %}
{% include '@SyliusShop/Common/Form/_address.html.twig' with {'form': form.shippingAddress, 'order': order, 'type': 'shipping'} %}
{{ form_row(form.differentBillingAddress,sylius_test_form_attribute('different-billing-address')|merge({'attr': {'data-toggles': 'sylius-billing-address'}, 'label_attr': {'data-test-different-billing-address-label': ''}})) }}
{{ form_row(form.differentBillingAddress, sylius_merge_recursively(sylius_test_form_attribute('different-billing-address'), {'attr': {'data-toggles': 'sylius-billing-address'}, 'label_attr': {'data-test-different-billing-address-label': ''}} )) }}

{{ sonata_block_render_event('sylius.shop.checkout.address.shipping_address_form', {'order': order}) }}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% endif %}
</div>

{% if form.provinceCode is defined %}a
{% if form.provinceCode is defined %}
{{ form_errors(form) }}
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="one field" id="sylius-api-login">
{{ form_errors(form.email, sylius_test_form_attribute('login-errors')) }}
{% set path = path('sylius_shop_ajax_user_check_action') %}
{{ form_row(form.email, sylius_test_form_attribute('login-email')|merge({'attr': {'data-url': path}})) }}
{{ form_row(form.email, sylius_merge_recursively(sylius_test_form_attribute('login-email'), {'attr': {'data-url': path}})) }}

<div class="ui action input" id="sylius-api-login-form">
<input type="password" placeholder="{{ 'sylius.ui.password'|trans }}">
Expand Down
4 changes: 4 additions & 0 deletions src/Sylius/Bundle/UiBundle/Resources/config/services/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@
<service id="sylius.twig.extension.sort_by" class="Sylius\Bundle\UiBundle\Twig\SortByExtension" public="false">
<tag name="twig.extension" />
</service>

<service id="sylius.twig.extension.merge_recursively" class="Sylius\Bundle\UiBundle\Twig\MergeRecursivelyExtension">
<tag name="twig.extension" />
</service>
</services>
</container>
36 changes: 36 additions & 0 deletions src/Sylius/Bundle/UiBundle/Twig/MergeRecursivelyExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\UiBundle\Twig;

use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class MergeRecursivelyExtension extends AbstractExtension
{
/**
* @return TwigFunction[]
*/
public function getFunctions(): array
{
return [
new TwigFunction(
'sylius_merge_recursively',
function (array $firstArray, array $secondArray): array {
return array_merge_recursive($firstArray, $secondArray);
},
['is_safe' => ['html']]
),
];
}
}

0 comments on commit f765ed4

Please sign in to comment.