Skip to content

Commit

Permalink
Change way to group routes and display it in setting form
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Sep 3, 2024
1 parent 2b2cae9 commit d1e4c4b
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 168 deletions.
14 changes: 9 additions & 5 deletions src/Form/Type/Settings/NoCommerceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'monsieurbiz.nocommerce.ui.form.field.routes_to_enable.label',
'required' => false,
'multiple' => true,
'expanded' => true,
'expanded' => false,
'choices' => $this->getEnabledRouteChoices(),
]);
}
Expand All @@ -77,10 +77,14 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
private function getEnabledRouteChoices(): array
{
$allRoutes = ConfigInterface::ROUTES_BY_GROUP;
$choices = [];

foreach ($allRoutes as $group => $routes) {
foreach ($routes as $route) {
$choices[$group][$route] = $route;
}
}

return array_combine(
array_map(static fn ($key) => 'monsieurbiz.nocommerce.ui.' . $key, array_keys($allRoutes)),
array_keys($allRoutes)
);
return $choices;
}
}
17 changes: 14 additions & 3 deletions src/Kernel/SyliusNoCommerceKernelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ public function getRoutesToRemove(): array
$routesToEnable = $featuresProvider->getRoutesToEnable();

foreach ($routesToEnable as $route) {
if (isset($this->routesToRemove[$route])) {
unset($this->routesToRemove[$route]);
}
$this->enableRoute($route);
}

foreach ($this->routesToRemove as $routes) {
Expand All @@ -98,4 +96,17 @@ public function getRoutesToRemove(): array

return $routesToRemove;
}

private function enableRoute(string $route): void
{
foreach ($this->routesToRemove as $group => $routes) {
if (false !== ($key = array_search($route, $routes, true))) {
unset($this->routesToRemove[$group][$key]);
}

if (empty($this->routesToRemove[$group])) {
unset($this->routesToRemove[$group]);
}
}
}
}
217 changes: 105 additions & 112 deletions src/Model/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,181 +16,174 @@
interface ConfigInterface
{
public const ROUTES_BY_GROUP = [
// Customers & Account & Users
'customer' => [
/**
* Customers & Account & Users.
*/
'customer_admin' => [
'sylius_admin_partial_customer',
'sylius_admin_customer',
'api_customer',
],
'customer_shop' => [
'sylius_shop_log',
'sylius_shop_register',
'sylius_shop_request_password_reset_token',
'sylius_shop_password_reset',
'sylius_shop_user_request_verification_token',
'sylius_shop_user_verification',
'sylius_shop_account',
'sylius_shop_ajax_user_check_action',
],
'customer_api' => [
'api_customer',
'api_register_shop_users_post_collection',
'sylius_api_shop_authentication_token',
'sylius_shop_ajax_user_check_action',
],

// Products
'product' => [
/**
* Catalog.
*/
'catalog_admin' => [
'sylius_admin_product',
'sylius_admin_api_product',
'sylius_admin_ajax_product',
'sylius_shop_partial_product',
'sylius_shop_product',
'sylius_admin_partial_product',
'sylius_admin_ajax_generate_product_slug',
'api_product',
],

// Taxons
'taxon' => [
'sylius_admin_partial_taxon',
'sylius_admin_ajax_taxon',
'sylius_admin_taxon',
'sylius_admin_api_taxon',
'sylius_shop_partial_taxon',
'sylius_admin_ajax_generate_taxon_slug',
'sylius_admin_get_attribute_types',
'sylius_admin_get_product_attributes',
'sylius_admin_render_attribute_forms',
'sylius_admin_inventory',
'sylius_admin_tax_',
'sylius_admin_api_tax_',
],
'catalog_shop' => [
'sylius_shop_partial_product',
'sylius_shop_product',
'sylius_shop_partial_taxon',
'sylius_shop_partial_channel_menu_taxon_index',
'api_taxon',
],

// Checkout
'checkout' => [
'sylius_admin_api_checkout',
'sylius_shop_checkout',
'sylius_shop_register_after_checkout',
'catalog_api' => [
'sylius_admin_api_product',
'api_product',
'sylius_admin_api_taxon',
'api_taxon',
'api_tax',
],

// Addresses
'address' => [
/**
* Addresses.
*/
'address_shop' => [
'sylius_shop_account_address',
'sylius_admin_partial_address',
'sylius_shop_ajax_render_province_form',
],

// Orders
'order' => [
/**
* Orders.
*/
'order_admin' => [
'sylius_admin_order',
'sylius_admin_api_order',
'sylius_shop_account_order',
'sylius_shop_order',
'sylius_admin_partial_order',
'sylius_admin_customer_order',
'sylius_admin_api_customer_order',
'api_order',
],

// Adjustments
'adjustment' => [
'sylius_admin_api_adjustment',
'sylius_shop_ajax_render_province_form',
'api_adjustment',
],

// Promotions
'promotion' => [
'sylius_admin_partial_address',
'sylius_admin_partial_promotion',
'sylius_admin_promotion',
'sylius_admin_api_promotion',
'sylius_admin_catalog_promotion',
'api_promo',
],

// Shipping and Shipments
'shipment' => [
'sylius_admin_partial_shipment',
'sylius_admin_ship',
'sylius_admin_api_ship',
'api_ship',
],

// Inventory
'inventory' => [
'sylius_admin_inventory',
],

// Attributes
'attribute' => [
'sylius_admin_get_attribute_types',
'sylius_admin_get_product_attributes',
'sylius_admin_render_attribute_forms',
],

// Payments
'payment' => [
'sylius_admin_payment',
'sylius_admin_get_payment',
'payum_',
'sylius_admin_api_payment',
'api_pay',
'sylius_admin_api_cart',
],

// PayPal
'paypal' => [
'order_shop' => [
'sylius_shop_account_order',
'sylius_shop_order',
'payum_',
'sylius_paypal',
'sylius_shop_ajax_cart',
'sylius_shop_partial_cart',
'sylius_shop_cart',
'sylius_shop_checkout',
'sylius_shop_register_after_checkout',
],

// Taxes
'tax' => [
'sylius_admin_tax_',
'sylius_admin_api_tax_',
'api_tax',
'order_api' => [
'sylius_admin_api_adjustment',
'sylius_admin_api_order',
'sylius_admin_api_customer_order',
'api_order',
'api_adjustment',
'sylius_admin_api_promotion',
'api_promo',
'sylius_admin_api_ship',
'api_ship',
'sylius_admin_api_payment',
'api_pay',
'api_cart',
'sylius_admin_api_checkout',
],

// Currencies
'currency' => [
/**
* Currencies.
*/
'currency_admin' => [
'sylius_admin_currency',
'sylius_admin_api_currency',
],
'currency_shop' => [
'sylius_shop_switch_currency',
],
'currency_api' => [
'api_currencies',
],

// Exchange rates
'exchange' => [
/**
* Exchange rates.
*/
'exchange_admin' => [
'sylius_admin_exchange',
'sylius_admin_api_exchange',
'api_exchange',
],

// Zones
'zone' => [
'exchange_api' => [
'api_exchange',
],
/**
* Zones.
*/
'zone_admin' => [
'sylius_admin_zone',
'sylius_admin_api_zone',
],
'zone_api' => [
'api_zone',
],

// Countries
'country' => [
/**
* Countries.
*/
'country_admin' => [
'sylius_admin_country',
'sylius_admin_api_country',
],
'country_api' => [
'api_countries',
],

// Provinces
'province' => [
/**
* Province.
*/
'province_admin' => [
'sylius_admin_api_province',
'sylius_admin_ajax_render_province_form',
'api_province',
],

// Carts
'cart' => [
'sylius_admin_api_cart',
'sylius_shop_ajax_cart',
'sylius_shop_partial_cart',
'sylius_shop_cart',
'api_cart',
'province_api' => [
'api_province',
],

// Dashboard
/**
* Dashboard.
*/
'dashboard' => [
'sylius_admin_dashboard_statistics',
],

// Others
'other' => [
/**
* Billing data.
*/
'billing_data' => [
'api_shop_billing',
'api_channels_shop',
],
Expand Down
26 changes: 2 additions & 24 deletions src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,6 @@ monsieurbiz:
disabled_firewall_contexts:
label: Firewalls to be disabled
enabled:
label: Enabled
label: Enabled, clear cache after modification
routes_to_enable:
label: Route to enable
customer: 'Customers'
product: 'Products'
taxon: 'Taxons'
checkout: 'Checkout'
address: 'Addresses'
order: 'Orders'
adjustment: 'Adjustements'
promotion: 'Promotions'
shipment: 'Shipments'
inventory: 'Inventory'
attribute: 'Attributes'
payment: 'Payments'
paypal: 'Paypal'
tax: 'Taxes'
currency: 'Currencies'
exchange: 'Exchanges rates'
zone: 'Zones'
country: 'Countries'
province: 'Provinces'
cart: 'Carts'
dashboard: 'Dashboard'
other: 'Autres'
label: 'Route to enable, clear cache after modification (⚠️ Beta: this feature is under development)'
Loading

0 comments on commit d1e4c4b

Please sign in to comment.