Skip to content

Commit

Permalink
OP-558: Sylius 2 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Oct 4, 2024
1 parent f27a33f commit 9a5c8ac
Show file tree
Hide file tree
Showing 30 changed files with 500 additions and 227 deletions.
3 changes: 1 addition & 2 deletions src/Form/Type/AutomaticBlacklistingConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use BitBag\SyliusBlacklistPlugin\Entity\FraudPrevention\AutomaticBlacklistingRuleInterface;
use Sylius\Bundle\AdminBundle\Form\Type\AddButtonType;
use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType;
use Sylius\Bundle\PromotionBundle\Form\Type\PromotionRuleType;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
Expand All @@ -30,10 +29,10 @@ final class AutomaticBlacklistingConfigurationType extends AbstractResourceType
private $attributeChoices;

public function __construct(
private array $rules,
string $dataClass,
array $attributeChoices,
array $validationGroups = [],
private array $rules,
) {
parent::__construct($dataClass, $validationGroups);
$this->attributeChoices = $attributeChoices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,38 @@

namespace BitBag\SyliusBlacklistPlugin\Form\Type;

use Sylius\Bundle\ResourceBundle\Form\Type\ResourceAutocompleteChoiceType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class CustomerAutocompleteChoiceType extends AbstractType
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType;

#[AsEntityAutocompleteField(
alias: 'sylius_admin_customer',
route: 'sylius_admin_entity_autocomplete',
)]
final class CustomerAutocompleteType extends AbstractType
{
public function __construct(
private string $customerClass,
) {
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'resource' => 'sylius.customer',
'choice_name' => 'email',
'class' => $this->customerClass,
'choice_label' => 'email',
'choice_value' => 'id',
]);
}

public function buildView(
FormView $view,
FormInterface $form,
array $options,
): void {
$view->vars['remote_criteria_type'] = 'contains';
$view->vars['remote_criteria_name'] = 'email';
}

public function getBlockPrefix(): string
{
return 'bitbag_sylius_customer_autocomplete_choice';
return 'bitbag_sylius_admin_customer_autocomplete';
}

public function getParent(): string
{
return ResourceAutocompleteChoiceType::class;
return BaseEntityAutocompleteType::class;
}
}
2 changes: 1 addition & 1 deletion src/Form/Type/FraudSuspicionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('customer', CustomerAutocompleteChoiceType::class, [
->add('customer', CustomerAutocompleteType::class, [
'label' => 'sylius.ui.customer',
'priority' => 1,
'constraints' => [
Expand Down
5 changes: 1 addition & 4 deletions src/Menu/FraudPreventionMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,35 @@ public function buildMenu(MenuBuilderEvent $menuBuilderEvent): void
$rootMenuItem = $menu
->addChild('bitbag_fraud_prevention')
->setLabel('bitbag_sylius_blacklist_plugin.ui.fraud_prevention')
->setLabelAttribute('icon', 'spy')
;

$rootMenuItem
->addChild(self::BLACKLISTING_RULE_TYPE_MENU_KEY, [
'route' => 'bitbag_sylius_blacklist_plugin_admin_blacklisting_rule_index',
])
->setLabel('bitbag_sylius_blacklist_plugin.ui.blacklisting_rules')
->setLabelAttribute('icon', 'hand paper')
;

$rootMenuItem
->addChild(self::AUTOMATIC_BLACKLISTING_CONFIGURATION_TYPE_MENU_KEY, [
'route' => 'bitbag_sylius_blacklist_plugin_admin_automatic_blacklisting_configuration_index',
])
->setLabel('bitbag_sylius_blacklist_plugin.ui.automatic_blacklisting_configurations')
->setLabelAttribute('icon', 'microchip')
;

$rootMenuItem
->addChild(self::FRAUD_SUSPICION_TYPE_MENU_KEY, [
'route' => 'bitbag_sylius_blacklist_plugin_admin_fraud_suspicion_index',
])
->setLabel('bitbag_sylius_blacklist_plugin.ui.fraud_suspicions')
->setLabelAttribute('icon', 'exclamation triangle')
;

$rootMenuItem
->addChild(self::AUTOMATIC_BLACKLISTING_CONFIGURATION_TYPE_MENU_KEY, [
'route' => 'bitbag_sylius_blacklist_plugin_admin_automatic_blacklisting_configuration_index',
])
->setLabel('bitbag_sylius_blacklist_plugin.ui.automatic_blacklisting_configurations')
->setLabelAttribute('icon', 'cog')
;
}
}
2 changes: 1 addition & 1 deletion src/Resources/config/routing/admin/fraud_suspicion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bitbag_sylius_blacklist_plugin_admin_fraud_suspicion:
icon: clipboard list
type: sylius.resource

bitbag_sylius_blacklist_plugin_admin_fraud_suspicion_show:
sylius_admin_fraud_suspicion_show:
path: fraud-suspicions/{id}
methods: [GET]
defaults:
Expand Down
7 changes: 6 additions & 1 deletion src/Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@

<service id="bitbag.sylius_blacklist_plugin.form.type.automatic_blacklisting_configuration"
class="BitBag\SyliusBlacklistPlugin\Form\Type\AutomaticBlacklistingConfigurationType">
<argument>%bitbag.sylius_blacklist_plugin.automatic_blacklisting_rules%</argument>
<argument>%bitbag_sylius_blacklist_plugin.model.automatic_blacklisting_configuration.class%</argument>
<argument>%bitbag.sylius_blacklist_plugin.form.type.automatic_blacklisting_configuration.validation_groups%</argument>
<argument>%bitbag.sylius_blacklist_plugin.form.type.validation_groups%</argument>
<argument>%bitbag.sylius_blacklist_plugin.automatic_blacklisting_rules%</argument>
<tag name="form.type" />
</service>
<service id="bitbag.sylius_blacklist_plugin.form.type.automatic_blacklisting_rule"
Expand All @@ -70,5 +70,10 @@
<argument>%bitbag.sylius_blacklist_plugin.automatic_blacklisting_rules%</argument>
<tag name="form.type" />
</service>
<service id="bitbag.sylius_blacklist_plugin.form.type.customer_autocomplete" class="BitBag\SyliusBlacklistPlugin\Form\Type\CustomerAutocompleteType" >
<argument>%sylius.model.customer.class%</argument>
<tag name="form.type" />
<tag name="ux.entity_autocomplete_field" />
</service>
</services>
</container>
36 changes: 34 additions & 2 deletions src/Resources/config/services/twig/component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
>
<services>
<service
id="bitbag.sylius_blacklist_plugin.twig.component.automatic_blacklisting_configuration.form"
id="bitbag_sylius_blacklist_plugin.twig.component.automatic_blacklisting_configuration.form"
class="Sylius\Bundle\UiBundle\Twig\Component\ResourceFormComponent"
>
<argument type="service" id="bitbag_sylius_blacklist_plugin.repository.automatic_blacklisting_configuration" />
Expand All @@ -17,9 +17,41 @@

<tag
name="sylius.live_component"
key="bitbag_sylius_blacklist_plugin:automatic_blacklisting_configuration:form"
key="sylius_admin:automatic_blacklisting_configuration:form"
template="@BitBagSyliusBlacklistPlugin/AutomaticBlacklistingConfiguration/Admin/form.html.twig"
/>
</service>

<service
id="bitbag_sylius_blacklist_plugin.twig.component.blacklisting_rule.form"
class="Sylius\Bundle\UiBundle\Twig\Component\ResourceFormComponent"
>
<argument type="service" id="bitbag_sylius_blacklist_plugin.repository.blacklisting_rule" />
<argument type="service" id="form.factory" />
<argument>%bitbag_sylius_blacklist_plugin.model.blacklisting_rule.class%</argument>
<argument>BitBag\SyliusBlacklistPlugin\Form\Type\BlacklistingRuleType</argument>

<tag
name="sylius.live_component"
key="sylius_admin:blacklisting_rule:form"
template="@BitBagSyliusBlacklistPlugin/BlacklistingRule/Admin/form.html.twig"
/>
</service>

<service
id="bitbag_sylius_blacklist_plugin.twig.component.fraud_suspicion.form"
class="Sylius\Bundle\UiBundle\Twig\Component\ResourceFormComponent"
>
<argument type="service" id="bitbag_sylius_blacklist_plugin.repository.fraud_suspicion" />
<argument type="service" id="form.factory" />
<argument>%bitbag_sylius_blacklist_plugin.model.fraud_suspicion.class%</argument>
<argument>BitBag\SyliusBlacklistPlugin\Form\Type\FraudSuspicionType</argument>

<tag
name="sylius.live_component"
key="sylius_admin:fraud_suspicion:form"
template="@BitBagSyliusBlacklistPlugin/FraudSuspicion/Admin/form.html.twig"
/>
</service>
</services>
</container>
15 changes: 15 additions & 0 deletions src/Resources/config/services/twig/extension.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>

<container
xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"
>
<services>
<service id="bitbag_sylius_blacklist_plugin.twig.extension.labels.automatic_blacklisting_configuration"
class="BitBag\SyliusBlacklistPlugin\Twig\AutomaticBlacklistingConfigurationLabelsExtension">
<argument>%bitbag.sylius_blacklist_plugin.automatic_blacklisting_rules%</argument>
<tag name="twig.extension"/>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
twig_hooks:
hooks:
'bitbag_sylius_blacklist_plugin.automatic_blacklisting_configuration.create.content':
'sylius_admin.automatic_blacklisting_configuration.create.content':
form:
component: 'bitbag_sylius_blacklist_plugin:automatic_blacklisting_configuration:form'
component: 'sylius_admin:automatic_blacklisting_configuration:form'
props:
resource: '@=_context.resource'
form: '@=_context.form'
configuration:
render_rest: false
'bitbag_sylius_blacklist_plugin.automatic_blacklisting_configuration.create.content.form':
'sylius_admin.automatic_blacklisting_configuration.create.content.form':
sections:
template: '@SyliusAdmin/promotion/form/sections.html.twig'
template: '@BitBagSyliusBlacklistPlugin/AutomaticBlacklistingConfiguration/Admin/form.html.twig'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
twig_hooks:
hooks:
'sylius_admin.automatic_blacklisting_configuration.update.content':
form:
component: 'sylius_admin:automatic_blacklisting_configuration:form'
props:
resource: '@=_context.resource'
form: '@=_context.form'
configuration:
method: 'PUT'
'sylius_admin.automatic_blacklisting_configuration.update.content.form':
sections:
template: '@BitBagSyliusBlacklistPlugin/AutomaticBlacklistingConfiguration/Admin/form.html.twig'
13 changes: 13 additions & 0 deletions src/Resources/config/twig_hooks/blacklisting_rule/create.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
twig_hooks:
hooks:
'sylius_admin.blacklisting_rule.create.content':
form:
component: 'sylius_admin:blacklisting_rule:form'
props:
resource: '@=_context.resource'
form: '@=_context.form'
configuration:
render_rest: false
'sylius_admin.blacklisting_rule.create.content.form':
sections:
template: '@BitBagSyliusBlacklistPlugin/BlacklistingRule/Admin/form.html.twig'
13 changes: 13 additions & 0 deletions src/Resources/config/twig_hooks/blacklisting_rule/update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
twig_hooks:
hooks:
'sylius_admin.blacklisting_rule.update.content':
form:
component: 'sylius_admin:blacklisting_rule:form'
props:
resource: '@=_context.resource'
form: '@=_context.form'
configuration:
method: 'PUT'
'sylius_admin.blacklisting_rule.update.content.form':
sections:
template: '@BitBagSyliusBlacklistPlugin/BlacklistingRule/Admin/form.html.twig'
13 changes: 13 additions & 0 deletions src/Resources/config/twig_hooks/fraud_suspicion/create.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
twig_hooks:
hooks:
'sylius_admin.fraud_suspicion.create.content':
form:
component: 'sylius_admin:fraud_suspicion:form'
props:
resource: '@=_context.resource'
form: '@=_context.form'
configuration:
render_rest: false
'sylius_admin.fraud_suspicion.create.content.form':
sections:
template: '@BitBagSyliusBlacklistPlugin/FraudSuspicion/Admin/form.html.twig'
5 changes: 5 additions & 0 deletions src/Resources/config/twig_hooks/fraud_suspicion/show.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
twig_hooks:
hooks:
'sylius_admin.fraud_suspicion.show.content':
general:
template: '@BitBagSyliusBlacklistPlugin/FraudSuspicion/Admin/show.html.twig'
13 changes: 13 additions & 0 deletions src/Resources/config/twig_hooks/fraud_suspicion/update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
twig_hooks:
hooks:
'sylius_admin.fraud_suspicion.update.content':
form:
component: 'sylius_admin:fraud_suspicion:form'
props:
resource: '@=_context.resource'
form: '@=_context.form'
configuration:
method: 'PUT'
'sylius_admin.fraud_suspicion.update.content.form':
sections:
template: '@BitBagSyliusBlacklistPlugin/FraudSuspicion/Admin/form.html.twig'
5 changes: 4 additions & 1 deletion src/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
bitbag_sylius_blacklist_plugin:
ui:
blacklisting_rules: Blacklisting rules
blacklisting_rule: Blacklisting rule
fraud_suspicions: Fraud suspicions
fraud_suspicion: Fraud suspicion
manage_blacklisting_rules: Manage blacklisting rules
manage_fraud_suspicions: Manage fraud suspicions
edit_fraud_suspicion: Edit fraud suspicion
Expand All @@ -18,6 +20,7 @@ bitbag_sylius_blacklist_plugin:
mark_suspicious: Mark suspicious
mark_blacklisted: Mark blacklisted
mark_neutral: Mark neutral
automatic_blacklisting_configuration: Auto-block rules
automatic_blacklisting_configurations: Auto-block rules
configure_automatic_blacklisting_configurations: Configure auto-blacklisitng
new_automatic_blacklisting_configuration: Add new automatic blacklisting configuration
Expand Down Expand Up @@ -71,4 +74,4 @@ bitbag_sylius_blacklist_plugin:
date_modifier: Date modifier
per_day: Per day
per_week: Per week
per_month: Per month
per_month: Per month
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% form_theme form '@BitBagSyliusBlacklistPlugin/Form/theme.html.twig' %}

<div class="container-xl" {{ attributes }}>
{{ form_start(form, {'attr': {'class': 'ui loadable form', 'novalidate': 'novalidate', 'id': form.vars.id}}) }}
{% if hookable_metadata.configuration.method is defined %}
<input type="hidden" name="_method" value="{{ hookable_metadata.configuration.method }}"/>
{% endif %}
{{ form_errors(form) }}
{{ form_widget(form._token) }}

<div class="card mb-3">
<div class="card-header">
<h3 class="card-title">{{ 'sylius.ui.configuration'|trans }}</h3>
</div>
<div class="card-body">
<div class="row align-items-center">
<div class="col-12 col-md-6">
{{ form_row(form.name) }}
</div>
<div class="col-12">
{{ form_row(form.channels) }}
</div>
<div class="col-12">
{{ form_row(form.enabled) }}
</div>
<div class="col-12">
{{ form_row(form.addFraudSuspicion) }}
</div>
<div class="col-12">
{{ form_row(form.permittedFraudSuspicionsNumber) }}
</div>
<div class="col-12">
{{ form_row(form.permittedFraudSuspicionsTime) }}
</div>
</div>
</div>
</div>

<div class="card mb-3">
<div class="card-header">
<h3 class="card-title">{{ 'bitbag_sylius_blacklist_plugin.form.automatic_blacklisting_rule.rules'|trans }}</h3>
</div>
<div class="card-body">
<div class="row align-items-center">
<div class="col-6">
{{ form_row(form.rules, {label: false}) }}
</div>
</div>
</div>
</div>

{{ form_end(form, {render_rest: hookable.configuration.render_rest|default(false)}) }}
</div>
Loading

0 comments on commit 9a5c8ac

Please sign in to comment.