Skip to content

Commit

Permalink
Merge branch '2.0' into bootstrap-admin-panel
Browse files Browse the repository at this point in the history
* 2.0:
  Replace sm_can function to sylius_sm_can function
  [AbstractionStateMachine] Add twig extension
  • Loading branch information
GSadee committed May 15, 2024
2 parents f42496c + 1766acc commit 36e06c0
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/Sylius/Abstraction/StateMachine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"winzou/state-machine": "^0.4",
"winzou/state-machine-bundle": "^0.6"
},
"suggest": {
"twig/twig": "Access the state machine in your twig templates (^2.12|^3.3)"
},
"require-dev": {
"matthiasnoback/symfony-config-test": "^4.2",
"phpunit/phpunit": "^9.5",
Expand Down
5 changes: 5 additions & 0 deletions src/Sylius/Abstraction/StateMachine/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@
<tag name="sylius.state_machine" key="winzou_state_machine" />
</service>
<service id="Sylius\Abstraction\StateMachine\StateMachineInterface $winzouStateMachine" alias="sylius_abstraction.state_machine.adapter.winzou_state_machine" />

<service id="sylius_abstraction.twig.extension.state_machine" class="Sylius\Abstraction\StateMachine\Twig\StateMachineExtension">
<argument type="service" id="sylius_abstraction.state_machine" />
<tag name="twig.extension" />
</service>
</services>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* 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\Abstraction\StateMachine\Twig;

use Sylius\Abstraction\StateMachine\StateMachineInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class StateMachineExtension extends AbstractExtension
{
public function __construct(private readonly StateMachineInterface $stateMachine)
{
}

public function getFunctions(): array
{
return [
new TwigFunction('sylius_sm_can', $this->stateMachine->can(...)),
new TwigFunction('sylius_sm_transitions', $this->stateMachine->getEnabledTransitions(...)),
];
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set order = hookable_metadata.context.resource %}

{% if sm_can(order, constant('Sylius\\Component\\Order\\OrderTransitions::TRANSITION_CANCEL'), constant('Sylius\\Component\\Order\\OrderTransitions::GRAPH')) %}
{% if sylius_sm_can(order, constant('Sylius\\Component\\Order\\OrderTransitions::GRAPH'), constant('Sylius\\Component\\Order\\OrderTransitions::TRANSITION_CANCEL')) %}
{% from '@SyliusAdmin/shared/helper/icon.html.twig' import icon as icon %}

<form action="{{ path('sylius_admin_order_cancel', {'id': order.id}) }}" method="POST" novalidate>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set order = hookable_metadata.context.resource %}
{% set payment = hookable_metadata.context.payment %}

{% if sm_can(payment, constant('Sylius\\Component\\Payment\\PaymentTransitions::TRANSITION_COMPLETE'), constant('Sylius\\Component\\Payment\\PaymentTransitions::GRAPH')) %}
{% if sylius_sm_can(payment, constant('Sylius\\Component\\Payment\\PaymentTransitions::GRAPH'), constant('Sylius\\Component\\Payment\\PaymentTransitions::TRANSITION_COMPLETE')) %}
{% from '@SyliusAdmin/shared/helper/icon.html.twig' import icon as icon %}

<form action="{{ path('sylius_admin_order_payment_complete', {'orderId': order.id, 'id': payment.id}) }}" method="POST" novalidate>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set order = hookable_metadata.context.resource %}
{% set payment = hookable_metadata.context.payment %}

{% if sm_can(payment, constant('Sylius\\Component\\Payment\\PaymentTransitions::TRANSITION_REFUND'), constant('Sylius\\Component\\Payment\\PaymentTransitions::GRAPH')) %}
{% if sylius_sm_can(payment, constant('Sylius\\Component\\Payment\\PaymentTransitions::GRAPH'), constant('Sylius\\Component\\Payment\\PaymentTransitions::TRANSITION_REFUND')) %}
{% from '@SyliusAdmin/shared/helper/icon.html.twig' import icon as icon %}

<form action="{{ path('sylius_admin_order_payment_refund', {'orderId': order.id, 'id': payment.id}) }}" method="POST" novalidate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% set labeled = options.labeled is defined ? options.labeled : true %}

{% if sm_can(data, options.transition, options.graph) %}
{% if sylius_sm_can(data, options.graph, options.transition) %}
<form action="{{ path(options.link.route, options.link.parameters) }}" method="post">
<input type="hidden" name="_csrf_token" value="{{ csrf_token(data.id) }}">
<input type="hidden" name="_method" value="PUT">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% form_theme form '@SyliusAdmin/shared/form_theme.html.twig' %}

{% if sm_can(shipment, 'ship', 'sylius_shipment') %}
{% if sylius_sm_can(shipment, 'sylius_shipment', 'ship') %}
<div {{ attributes }}>
{{ form_start(form, {'action': path('sylius_admin_shipment_ship', {id: shipment.id}), 'attr': {'class': 'ui loadable form', 'novalidate': 'novalidate'}}) }}
<input type="hidden" name="_method" value="PUT">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set labeled = options.labeled is defined ? options.labeled : true %}

{% if sm_can(data, options.transition, options.graph) %}
{% if sylius_sm_can(data, options.graph, options.transition) %}
<form action="{{ path(options.link.route, options.link.parameters) }}" method="post">
<input type="hidden" name="_csrf_token" value="{{ csrf_token(data.id) }}">
<input type="hidden" name="_method" value="PUT">
Expand Down

0 comments on commit 36e06c0

Please sign in to comment.