On this weblog, we’re about to study, methods to create customized tab on the again workplace product web page. So, we are going to outline our personal Symfony providers within the module and can use current parts.
You possibly can discover our PrestaShop Growth Providers and a wide variety of high quality PrestaShop Modules.
Right here, we’re exhibiting the method step-by-step with an instance module ‘wktestmodule‘
First, create a module, with a composer.json
file as per your requirement.
Step 1: Create the module class
Right here, we’ve got created the module class file “wktestmodule/wktestmodule.php“
On this class, we’re initializing the module, product controllers tab, and type fields.
declare(strict_types=1); use PrestaShopModuleWkTestModuleFormModifierProductFormModifier; use PrestaShopPrestaShopCoreDomainProductValueObjectProductId; class WkTestModule extends Module { public perform __construct() { $this->title = 'wktestmodule'; $this->tab = 'front_office_features'; $this->model = '1.0.0'; $this->need_instance = 0; $this->bootstrap = true; father or mother::__construct(); $this->displayName = $this->l('Webkul'); $this->description = $this->l('Kind sorts inside PrestaShop'); $this->ps_versions_compliancy = ['min' => '8.1', 'max' => _PS_VERSION_]; } /** * @return bool */ public perform set up() { return father or mother::set up() && $this->registerHook(['actionProductFormBuilderModifier']); } /** * Modify product type builder * * @param array $params */ public perform hookActionProductFormBuilderModifier(array $params): void { /** @var ProductFormModifier $productFormModifier */ $productFormModifier = $this->get(ProductFormModifier::class); $productId = isset($params['id']) ? new ProductId((int) $params['id']) : null; $productFormModifier->modify($productId, $params['form_builder']); } }
After that, Within the console in your module root run the command composer dump-autoload
. This may generate a vendor folder containing an autoload.php file which permits using your namespace or the courses outlined within the classmap.
Step 2: Outline the service
Create a providers.yml file contained in the wktestmodule/config/providers.yml folder
Within the given code, we’ve got outlined our providers. These will likely be used for type creation and type dealing with. Service is created contained in the wktestmodule/src/Kind/Modifier folder
providers: PrestaShopModuleWkTestModuleFormModifierProductFormModifier: autowire: true public: true arguments: $formBuilderModifier: '@type.form_builder_modifier' PrestaShopModuleWkTestModuleFormTypeCustomTabType: class: PrestaShopModuleWkTestModuleFormTypeCustomTabType father or mother: 'type.kind.translatable.conscious' public: true tags: - { title: type.kind }
Step 3: Create a CustomTabType class
The tab class is created contained in the wktestmodule/src/Kind/Kind folder
declare(strict_types=1); namespace PrestaShopModuleDemoProductFormFormType; use PrestaShopBundleFormAdminTypeTranslatorAwareType; use SymfonyComponentFormExtensionCoreTypeTextType; use SymfonyComponentFormFormBuilderInterface; use SymfonyComponentOptionsResolverOptionsResolver; use SymfonyComponentTranslationTranslatorInterface; use SymfonyComponentValidatorConstraintsNotBlank; use SymfonyComponentValidatorConstraintsPositiveOrZero; use SymfonyComponentValidatorConstraintsType; class CustomTabType extends TranslatorAwareType { /** * @var Forex */ non-public $defaultCurrency; /** * @param TranslatorInterface $translator * @param array $locales * @param Forex $defaultCurrency */ public perform __construct( TranslatorInterface $translator, array $locales, Forex $defaultCurrency ) { father or mother::__construct($translator, $locales); $this->defaultCurrency = $defaultCurrency; } /** * {@inheritDoc} */ public perform buildForm(FormBuilderInterface $builder, array $choices) { father or mother::buildForm($builder, $choices); $builder ->add('webkul_custom_field', TextType::class, [ 'label' => $this->trans('Webkul Custom Field', 'Modules.Demoproductform.Admin'), 'label_tag_name' => 'h3', // 'currency' => $this->defaultCurrency->iso_code, 'required' => false, 'constraints' => [ new NotBlank(), new Type(['type' => 'float']), new PositiveOrZero(), ], ]) ; } /** * {@inheritDoc} */ public perform configureOptions(OptionsResolver $resolver) { father or mother::configureOptions($resolver); $resolver ->setDefaults([ 'label' => $this->trans('Webkul Tab', 'Modules.Demoproductform.Admin'), ]) ; } }
Step 4: Create a service ProductFormModifier class
declare(strict_types=1); namespace PrestaShopModuleWkTestModuleFormModifier; use PrestaShopModuleWkTestModuleEntityCustomProduct; use PrestaShopModuleWkTestModuleFormTypeCustomTabType; use PrestaShopPrestaShopCoreDomainProductValueObjectProductId; use PrestaShopBundleFormFormBuilderModifier; use SymfonyComponentFormFormBuilderInterface; use SymfonyComponentTranslationTranslatorInterface; remaining class ProductFormModifier { /** * @var TranslatorInterface */ non-public $translator; /** * @var FormBuilderModifier */ non-public $formBuilderModifier; /** * @param TranslatorInterface $translator * @param FormBuilderModifier $formBuilderModifier */ public perform __construct( TranslatorInterface $translator, FormBuilderModifier $formBuilderModifier ) { $this->translator = $translator; $this->formBuilderModifier = $formBuilderModifier; } /** * @param ProductId|null $productId * @param FormBuilderInterface $productFormBuilder */ public perform modify( ?ProductId $productId, FormBuilderInterface $productFormBuilder ): void { $idValue = $productId ? $productId->getValue() : null; $customProduct = new CustomProduct($idValue); $this->addCustomTab($customProduct, $productFormBuilder); } /** * @param CustomProduct $customProduct * @param FormBuilderInterface $productFormBuilder */ non-public perform addCustomTab(CustomProduct $customProduct, FormBuilderInterface $productFormBuilder): void { $this->formBuilderModifier->addAfter( $productFormBuilder, 'extra_modules', 'custom_tab', CustomTabType::class, [ 'data' => [ 'webkul_custom_field' => $customProduct->custom_price, ], ] ); } }
The above module makes use of a Kind Builder Modifier (FormBuilderModifier) and provides a brand new Tab “Webkul Tab” with a discipline “Webkul Customized Area”.
After efficiently set up of the above module. You’ll get the outcome as follows

NOTE: “actionProductFormBuilderModifier” helps in PrestaShop Model V8.1.0
So, this hook will work within the under PrestaShop Variations.
That’s all.
You additionally study to save lots of and show customized type discipline utilizing PrestaShop Hook.
If you’re going through any points or doubts within the above course of, please be at liberty to contact us within the remark part.
I might be comfortable to assist.
On this weblog, we’re about to study, methods to create customized tab on the again workplace product web page. So, we are going to outline our personal Symfony providers within the module and can use current parts.
You possibly can discover our PrestaShop Growth Providers and a wide variety of high quality PrestaShop Modules.
Right here, we’re exhibiting the method step-by-step with an instance module ‘wktestmodule‘
First, create a module, with a composer.json
file as per your requirement.
Step 1: Create the module class
Right here, we’ve got created the module class file “wktestmodule/wktestmodule.php“
On this class, we’re initializing the module, product controllers tab, and type fields.
declare(strict_types=1); use PrestaShopModuleWkTestModuleFormModifierProductFormModifier; use PrestaShopPrestaShopCoreDomainProductValueObjectProductId; class WkTestModule extends Module { public perform __construct() { $this->title = 'wktestmodule'; $this->tab = 'front_office_features'; $this->model = '1.0.0'; $this->need_instance = 0; $this->bootstrap = true; father or mother::__construct(); $this->displayName = $this->l('Webkul'); $this->description = $this->l('Kind sorts inside PrestaShop'); $this->ps_versions_compliancy = ['min' => '8.1', 'max' => _PS_VERSION_]; } /** * @return bool */ public perform set up() { return father or mother::set up() && $this->registerHook(['actionProductFormBuilderModifier']); } /** * Modify product type builder * * @param array $params */ public perform hookActionProductFormBuilderModifier(array $params): void { /** @var ProductFormModifier $productFormModifier */ $productFormModifier = $this->get(ProductFormModifier::class); $productId = isset($params['id']) ? new ProductId((int) $params['id']) : null; $productFormModifier->modify($productId, $params['form_builder']); } }
After that, Within the console in your module root run the command composer dump-autoload
. This may generate a vendor folder containing an autoload.php file which permits using your namespace or the courses outlined within the classmap.
Step 2: Outline the service
Create a providers.yml file contained in the wktestmodule/config/providers.yml folder
Within the given code, we’ve got outlined our providers. These will likely be used for type creation and type dealing with. Service is created contained in the wktestmodule/src/Kind/Modifier folder
providers: PrestaShopModuleWkTestModuleFormModifierProductFormModifier: autowire: true public: true arguments: $formBuilderModifier: '@type.form_builder_modifier' PrestaShopModuleWkTestModuleFormTypeCustomTabType: class: PrestaShopModuleWkTestModuleFormTypeCustomTabType father or mother: 'type.kind.translatable.conscious' public: true tags: - { title: type.kind }
Step 3: Create a CustomTabType class
The tab class is created contained in the wktestmodule/src/Kind/Kind folder
declare(strict_types=1); namespace PrestaShopModuleDemoProductFormFormType; use PrestaShopBundleFormAdminTypeTranslatorAwareType; use SymfonyComponentFormExtensionCoreTypeTextType; use SymfonyComponentFormFormBuilderInterface; use SymfonyComponentOptionsResolverOptionsResolver; use SymfonyComponentTranslationTranslatorInterface; use SymfonyComponentValidatorConstraintsNotBlank; use SymfonyComponentValidatorConstraintsPositiveOrZero; use SymfonyComponentValidatorConstraintsType; class CustomTabType extends TranslatorAwareType { /** * @var Forex */ non-public $defaultCurrency; /** * @param TranslatorInterface $translator * @param array $locales * @param Forex $defaultCurrency */ public perform __construct( TranslatorInterface $translator, array $locales, Forex $defaultCurrency ) { father or mother::__construct($translator, $locales); $this->defaultCurrency = $defaultCurrency; } /** * {@inheritDoc} */ public perform buildForm(FormBuilderInterface $builder, array $choices) { father or mother::buildForm($builder, $choices); $builder ->add('webkul_custom_field', TextType::class, [ 'label' => $this->trans('Webkul Custom Field', 'Modules.Demoproductform.Admin'), 'label_tag_name' => 'h3', // 'currency' => $this->defaultCurrency->iso_code, 'required' => false, 'constraints' => [ new NotBlank(), new Type(['type' => 'float']), new PositiveOrZero(), ], ]) ; } /** * {@inheritDoc} */ public perform configureOptions(OptionsResolver $resolver) { father or mother::configureOptions($resolver); $resolver ->setDefaults([ 'label' => $this->trans('Webkul Tab', 'Modules.Demoproductform.Admin'), ]) ; } }
Step 4: Create a service ProductFormModifier class
declare(strict_types=1); namespace PrestaShopModuleWkTestModuleFormModifier; use PrestaShopModuleWkTestModuleEntityCustomProduct; use PrestaShopModuleWkTestModuleFormTypeCustomTabType; use PrestaShopPrestaShopCoreDomainProductValueObjectProductId; use PrestaShopBundleFormFormBuilderModifier; use SymfonyComponentFormFormBuilderInterface; use SymfonyComponentTranslationTranslatorInterface; remaining class ProductFormModifier { /** * @var TranslatorInterface */ non-public $translator; /** * @var FormBuilderModifier */ non-public $formBuilderModifier; /** * @param TranslatorInterface $translator * @param FormBuilderModifier $formBuilderModifier */ public perform __construct( TranslatorInterface $translator, FormBuilderModifier $formBuilderModifier ) { $this->translator = $translator; $this->formBuilderModifier = $formBuilderModifier; } /** * @param ProductId|null $productId * @param FormBuilderInterface $productFormBuilder */ public perform modify( ?ProductId $productId, FormBuilderInterface $productFormBuilder ): void { $idValue = $productId ? $productId->getValue() : null; $customProduct = new CustomProduct($idValue); $this->addCustomTab($customProduct, $productFormBuilder); } /** * @param CustomProduct $customProduct * @param FormBuilderInterface $productFormBuilder */ non-public perform addCustomTab(CustomProduct $customProduct, FormBuilderInterface $productFormBuilder): void { $this->formBuilderModifier->addAfter( $productFormBuilder, 'extra_modules', 'custom_tab', CustomTabType::class, [ 'data' => [ 'webkul_custom_field' => $customProduct->custom_price, ], ] ); } }
The above module makes use of a Kind Builder Modifier (FormBuilderModifier) and provides a brand new Tab “Webkul Tab” with a discipline “Webkul Customized Area”.
After efficiently set up of the above module. You’ll get the outcome as follows

NOTE: “actionProductFormBuilderModifier” helps in PrestaShop Model V8.1.0
So, this hook will work within the under PrestaShop Variations.
That’s all.
You additionally study to save lots of and show customized type discipline utilizing PrestaShop Hook.
If you’re going through any points or doubts within the above course of, please be at liberty to contact us within the remark part.
I might be comfortable to assist.