Skip to content

Commit

Permalink
Fix service definition
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienPapet committed Feb 2, 2023
1 parent 027ec1a commit ada744e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 80 deletions.
Expand Up @@ -27,9 +27,9 @@

namespace PrestaShopBundle\Form\Admin\Configure\ShopParameters\OrderStates;

use PrestaShop\PrestaShop\Adapter\Configuration;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\DefaultLanguage;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\Domain\Configuration\ShopConfigurationInterface;
use PrestaShop\PrestaShop\Core\MailTemplate\Layout\Layout;
use PrestaShop\PrestaShop\Core\MailTemplate\ThemeCatalogInterface;
use PrestaShopBundle\Form\Admin\Type\ColorPickerType;
Expand All @@ -40,6 +40,7 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
Expand All @@ -61,15 +62,17 @@ class OrderStateType extends TranslatorAwareType
* @param TranslatorInterface $translator
* @param array $locales
* @param ThemeCatalogInterface $themeCatalog
* @param Configuration $configuration
* @param UrlGeneratorInterface $routing
* @param ShopConfigurationInterface $configuration
*
* @throws \PrestaShop\PrestaShop\Core\Exception\InvalidArgumentException
*/
public function __construct(
TranslatorInterface $translator,
array $locales,
ThemeCatalogInterface $themeCatalog,
Configuration $configuration
UrlGeneratorInterface $routing,
ShopConfigurationInterface $configuration
) {
parent::__construct($translator, $locales);
$mailTheme = $configuration->get('PS_MAIL_THEME', 'modern');
Expand All @@ -84,7 +87,7 @@ public function __construct(
foreach ($mailLayouts as $mailLayout) {
$this->templates[$languageId][$mailLayout->getName()] = $mailLayout->getName();
$this->templateAttributes[$languageId][$mailLayout->getName()] = [
'data-preview' => $this->routing->generate(
'data-preview' => $routing->generate(
empty($mailLayout->getModuleName()) ?
'admin_mail_theme_preview_layout' :
'admin_mail_theme_preview_module_layout',
Expand Down
Expand Up @@ -26,7 +26,7 @@

namespace PrestaShopBundle\Form\Admin\Product;

use PrestaShop\PrestaShop\Adapter\Configuration;
use PrestaShop\PrestaShop\Core\Domain\Configuration\ShopConfigurationInterface;
use PrestaShopBundle\Form\Admin\Type\CommonAbstractType;
use PrestaShopBundle\Form\Admin\Type\DatePickerType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
Expand All @@ -43,20 +43,19 @@
*/
class ProductCombinationBulk extends CommonAbstractType
{
private $isoCode;
private $translator;
private $configuration;

public function __construct(TranslatorInterface $translator, Configuration $configuration)
public function __construct(TranslatorInterface $translator, ShopConfigurationInterface $configuration)
{
$this->translator = $translator;
$this->configuration = $configuration;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$is_stock_management = $this->configuration->get('PS_STOCK_MANAGEMENT');
$this->isoCode = $options['iso_code'];
$is_stock_management = $this->configuration->getBoolean('PS_STOCK_MANAGEMENT');
$isoCode = $options['iso_code'];

if ($is_stock_management) {
$builder->add('quantity', NumberType::class, [
Expand All @@ -69,7 +68,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'required' => false,
'label' => $this->translator->trans('Cost Price', [], 'Admin.Catalog.Feature'),
'attr' => ['data-display-price-precision' => self::PRESTASHOP_DECIMALS],
'currency' => $this->isoCode,
'currency' => $isoCode,
])
->add('impact_on_weight', NumberType::class, [
'required' => false,
Expand All @@ -78,13 +77,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('impact_on_price_te', MoneyType::class, [
'required' => false,
'label' => $this->translator->trans('Impact on price (tax excl.)', [], 'Admin.Catalog.Feature'),
'currency' => $this->isoCode,
'currency' => $isoCode,
])
->add('impact_on_price_ti', MoneyType::class, [
'required' => false,
'mapped' => false,
'label' => $this->translator->trans('Impact on price (tax incl.)', [], 'Admin.Catalog.Feature'),
'currency' => $this->isoCode,
'currency' => $isoCode,
])
->add('date_availability', DatePickerType::class, [
'required' => false,
Expand Down
17 changes: 11 additions & 6 deletions src/PrestaShopBundle/Form/Admin/Product/ProductCustomField.php
Expand Up @@ -26,30 +26,35 @@

namespace PrestaShopBundle\Form\Admin\Product;

use PrestaShop\PrestaShop\Adapter\LegacyContext;
use PrestaShopBundle\Form\Admin\Type\CommonAbstractType;
use PrestaShopBundle\Form\Admin\Type\TranslateType;
use Symfony\Component\Form\Extension\Core\Type as FormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* This form class is responsible to generate the product custom fields configuration form.
*/
class ProductCustomField extends CommonAbstractType
{
private $translator;
private $locales;
/**
* @var object|LegacyContext
*/
private $legacyContext;

/**
* Constructor.
*
* @param object $translator
* @param object $legacyContext
* @param TranslatorInterface $translator
* @param LegacyContext $legacyContext
*/
public function __construct($translator, $legacyContext)
public function __construct(TranslatorInterface $translator, LegacyContext $legacyContext)
{
$this->translator = $translator;
$this->locales = $legacyContext->getLanguages();
$this->legacyContext = $legacyContext;
}

/**
Expand All @@ -72,7 +77,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
new Assert\NotBlank(),
new Assert\Length(['min' => 2]),
]],
'locales' => $this->locales,
'locales' => $this->legacyContext->getLanguages(),
'hideTabs' => true,
'label' => $this->translator->trans('Label', [], 'Admin.Global'),
])
Expand Down
8 changes: 4 additions & 4 deletions src/PrestaShopBundle/Form/Admin/Product/ProductQuantity.php
Expand Up @@ -38,7 +38,7 @@
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Router;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Contracts\Translation\TranslatorInterface;

Expand All @@ -60,7 +60,7 @@ class ProductQuantity extends CommonAbstractType
*/
public $locales;
/**
* @var Router
* @var UrlGeneratorInterface
*/
private $router;
/**
Expand All @@ -72,13 +72,13 @@ class ProductQuantity extends CommonAbstractType
* Constructor.
*
* @param TranslatorInterface $translator
* @param Router $router
* @param UrlGeneratorInterface $router
* @param LegacyContext $legacyContext
* @param ConfigurationInterface $configuration
*/
public function __construct(
TranslatorInterface $translator,
Router $router,
UrlGeneratorInterface $router,
LegacyContext $legacyContext,
ConfigurationInterface $configuration
) {
Expand Down
18 changes: 7 additions & 11 deletions src/PrestaShopBundle/Form/Admin/Product/ProductSeo.php
Expand Up @@ -26,7 +26,6 @@

namespace PrestaShopBundle\Form\Admin\Product;

use Language;
use PrestaShop\PrestaShop\Adapter\LegacyContext;
use PrestaShop\PrestaShop\Core\Domain\Product\ValueObject\RedirectType;
use PrestaShopBundle\Form\Admin\Type\CommonAbstractType;
Expand All @@ -35,6 +34,7 @@
use Symfony\Component\Form\Extension\Core\Type as FormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Router;
use Symfony\Contracts\Translation\TranslatorInterface;

Expand All @@ -48,11 +48,7 @@ class ProductSeo extends CommonAbstractType
*/
public $context;
/**
* @var array<int|Language>
*/
private $locales;
/**
* @var Router
* @var UrlGeneratorInterface
*/
private $router;
/**
Expand All @@ -67,11 +63,10 @@ class ProductSeo extends CommonAbstractType
* @param LegacyContext $legacyContext
* @param Router $router
*/
public function __construct($translator, $legacyContext, $router)
public function __construct(TranslatorInterface $translator, LegacyContext $legacyContext, UrlGeneratorInterface $router)
{
$this->translator = $translator;
$this->context = $legacyContext;
$this->locales = $legacyContext->getLanguages();
$this->router = $router;
}

Expand All @@ -82,6 +77,7 @@ public function __construct($translator, $legacyContext, $router)
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$locales = $this->context->getLanguages();
$remoteUrls = [
RedirectType::TYPE_PRODUCT_PERMANENT => $this->context->getLegacyAdminLink('AdminProducts', true, ['ajax' => 1, 'action' => 'productsList', 'forceJson' => 1, 'disableCombination' => 1, 'exclude_packs' => 0, 'excludeVirtuals' => 0, 'limit' => 20]) . '&q=%QUERY',
RedirectType::TYPE_PRODUCT_TEMPORARY => $this->context->getLegacyAdminLink('AdminProducts', true, ['ajax' => 1, 'action' => 'productsList', 'forceJson' => 1, 'disableCombination' => 1, 'exclude_packs' => 0, 'excludeVirtuals' => 0, 'limit' => 20]) . '&q=%QUERY',
Expand All @@ -103,7 +99,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
'required' => false,
],
'locales' => $this->locales,
'locales' => $this->context->getLanguages(),
'hideTabs' => true,
'label' => $this->translator->trans('Meta title', [], 'Admin.Catalog.Feature'),
'label_attr' => [
Expand All @@ -128,7 +124,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
'required' => false,
],
'locales' => $this->locales,
'locales' => $locales,
'hideTabs' => true,
'label' => $this->translator->trans('Meta description', [], 'Admin.Catalog.Feature'),
'label_attr' => [
Expand All @@ -149,7 +145,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'class' => 'serp-watched-url',
],
],
'locales' => $this->locales,
'locales' => $locales,
'hideTabs' => true,
'label' => $this->translator->trans('Friendly URL', [], 'Admin.Catalog.Feature'),
]
Expand Down
@@ -1,6 +1,3 @@
imports:
- { resource: 'form_type/*' }

services:
_defaults:
public: false
Expand Down Expand Up @@ -52,20 +49,8 @@ services:
- "@prestashop.adapter.data_provider.feature"

PrestaShopBundle\Form\Admin\Product\ProductAttachement:
arguments:
- "@translator"
- '@prestashop.adapter.legacy.configuration'

PrestaShopBundle\Form\Admin\Product\ProductCombination:
arguments:
- "@translator"
- "@prestashop.adapter.legacy.context"
- '@prestashop.adapter.legacy.configuration'

PrestaShopBundle\Form\Admin\Product\ProductCustomField:
arguments:
- "@translator"
- "@prestashop.adapter.legacy.context"

PrestaShopBundle\Form\Admin\Product\ProductInformation:
arguments:
Expand Down Expand Up @@ -97,17 +82,7 @@ services:
- "@prestashop.adapter.legacy.context"

PrestaShopBundle\Form\Admin\Product\ProductQuantity:
arguments:
- "@translator"
- "@router"
- "@prestashop.adapter.legacy.context"
- '@prestashop.adapter.legacy.configuration'

PrestaShopBundle\Form\Admin\Product\ProductSeo:
arguments:
- "@translator"
- "@prestashop.adapter.legacy.context"
- "@router"

PrestaShopBundle\Form\Admin\Product\ProductShipping:
arguments:
Expand Down Expand Up @@ -135,10 +110,6 @@ services:
- "@prestashop.adapter.data_provider.currency"

PrestaShopBundle\Form\Admin\Product\ProductVirtual:
arguments:
- "@translator"
- '@prestashop.adapter.legacy.configuration'

PrestaShopBundle\Form\Admin\Product\ProductWarehouseCombination:
PrestaShopBundle\Form\Admin\Type\TypeaheadProductCollectionType:
arguments:
Expand All @@ -150,10 +121,6 @@ services:
- "@prestashop.adapter.data_provider.customer"

PrestaShopBundle\Form\Admin\Product\ProductCombinationBulk:
arguments:
- "@translator"
- "@prestashop.adapter.legacy.configuration"

PrestaShopBundle\Form\Admin\Product\ProductCategories:
arguments:
- "@translator"
Expand Down Expand Up @@ -324,6 +291,22 @@ services:
calls:
- { method: setTranslator, arguments: [ '@translator' ] }

PrestaShopBundle\Form\Admin\Catalog\Category\AbstractCategoryType:
arguments:
$customerGroupChoices: '@=service("prestashop.core.form.choice_provider.group_by_id").getChoices()'
$multistoreFeature: '@prestashop.adapter.feature.multistore'

PrestaShopBundle\Form\Admin\Catalog\Category\CategoryType:
arguments:
$customerGroupChoices: '@=service("prestashop.core.form.choice_provider.group_by_id").getChoices()'
$multistoreFeature: '@prestashop.adapter.feature.multistore'

PrestaShopBundle\Form\Admin\Catalog\Category\RootCategoryType:
arguments:
$customerGroupChoices: '@=service("prestashop.core.form.choice_provider.group_by_id").getChoices()'
$multistoreFeature: '@prestashop.adapter.feature.multistore'


PrestaShopBundle\Form\Admin\Sell\Category\DeleteCategoriesType:
arguments:
- '@=service("prestashop.core.form.choice_provider.category_delete_mode").getChoices()'
Expand Down Expand Up @@ -394,8 +377,8 @@ services:
arguments:
$genderChoices: '@=service("prestashop.adapter.form.choice_provider.gender_by_id_choice_provider").getChoices()'
$groupChoices: '@=service("prestashop.adapter.form.choice_provider.group_by_id_choice_provider").getChoices()'
$isB2bFeatureEnabled: '@=service("prestashop.adapter.form.choice_provider.risk_by_id_choice_provider").getChoices()'
$riskChoices: '@=service("prestashop.core.b2b.b2b_feature").isActive()'
$riskChoices: '@=service("prestashop.adapter.form.choice_provider.risk_by_id_choice_provider").getChoices()'
$isB2bFeatureEnabled: '@=service("prestashop.core.b2b.b2b_feature").isActive()'
$isPartnerOffersEnabled: '@=service("prestashop.adapter.legacy.configuration").get("PS_CUSTOMER_OPTIN")'

PrestaShopBundle\Form\Admin\Improve\International\Currencies\CurrencyType:
Expand Down Expand Up @@ -430,8 +413,8 @@ services:

PrestaShopBundle\Form\Admin\Configure\ShopParameters\Contact\ContactType:
arguments:
$isShopFeatureEnabled: '@prestashop.bundle.form.data_transformer.default_language_to_filled_array'
$singleDefaultLanguageArrayToFilledArrayDataTransformer: '@=service("prestashop.adapter.multistore_feature").isUsed()'
$singleDefaultLanguageArrayToFilledArrayDataTransformer: '@prestashop.bundle.form.data_transformer.default_language_to_filled_array'
$isShopFeatureEnabled: '@=service("prestashop.adapter.multistore_feature").isUsed()'

PrestaShopBundle\Form\Admin\Improve\Design\Pages\CmsPageCategoryType:
arguments:
Expand Down Expand Up @@ -988,6 +971,13 @@ services:
- '@prestashop.adapter.data_provider.module'
- '@prestashop.adapter.legacy.context'


PrestaShopBundle\Form\Admin\Configure\AdvancedParameters\Webservice\WebserviceKeyType:
arguments:
$isMultistoreFeatureUsed: '@=service("prestashop.adapter.multistore_feature").isUsed()'
$resourceChoices: '@=service("prestashop.adapter.form.choice_provider.resources_choice_provider").getChoices()'
$permissionChoices: '@=service("prestashop.core.form.choice_provider.permissions_choice_provider").getChoices()'

PrestaShopBundle\Form\Admin\Improve\International\Tax\TaxRulesGroupType:
arguments:
$isShopFeatureEnabled: '@=service("prestashop.adapter.multistore_feature").isUsed()'

0 comments on commit ada744e

Please sign in to comment.