Back to Top

PrestaShop data provider and handler

Updated 29 April 2022

In this blog we are going to discuss about saving data submitted from Symfony form, in PrestaShop . Here we are going to demonstrate PrestaShop, data provider and handler to save submitted data.

We are continuing this blog where we end the last one.

Step 7 :

Add below lines in services.yml

    public: true

    class: 'PrestaShop\Module\DemoForms\Form\DemoFirstTextType'
    parent: 'form.type.translatable.aware'
    public: true
      - { name: form.type }

    class: 'PrestaShop\Module\DemoForms\Form\DemoFirstTextFormDataProvider'
      - '@prestashop.module.demoforms.form.demo_first_text_data_configuration'

    class: 'PrestaShop\PrestaShop\Core\Form\Handler'
      - '@form.factory'
      - '@prestashop.core.hook.dispatcher'
      - '@prestashop.module.demoforms.form.demo_first_text_form_data_provider'
      - 'PrestaShop\Module\DemoForms\Form\DemoFirstTextType'
      - 'DemoFirst'

    class: PrestaShop\Module\DemoForms\Form\DemoFirstTextDataConfiguration
    arguments: ['@prestashop.adapter.legacy.configuration']

Services loads all the handler and data provider written in src/Form folder

Step 8 :

Add below line in DemoFirstController.php index function :

Searching for an experienced
Prestashop Company ?
Find out More
public function index(Request $request): Response
    $textFormDataHandler = $this->get(
    $textForm = $textFormDataHandler->getForm();
    if ($textForm->isSubmitted() && $textForm->isValid()) {
        $errors = $textFormDataHandler->save($textForm->getData());
        if (empty($errors)) {
                $this->trans('Successful update.', 'Admin.Notifications.Success')
            return $this->redirectToRoute('demo_first_form);
   return $this->render(
       ['demoForms' => $textForm->createView(),]

Here we added flash message to show on error and success of saving process using form handler.

Symfony form data provider, handler in Prestashop
Symfony form in PrestaShop

Step : 9

Add below lines in DemoFirstTextFormDataProvider.php in Form

namespace PrestaShop\Module\DemoForms\Form;
use PrestaShop\PrestaShop\Core\Configuration\DataConfigurationInterface;
use PrestaShop\PrestaShop\Core\Form\FormDataProviderInterface;

class DemoFirstTextFormDataProvider implements FormDataProviderInterface
    private $demoFirstTextDataConfiguration;

    public function __construct(DataConfigurationInterface $demoFirstTextDataConfiguration)
        $this->demoFirstTextDataConfiguration = $demoFirstTextDataConfiguration;

    public function getData(): array
        return $this->demoFirstTextDataConfiguration->getConfiguration();

    public function setData(array $data): array
        return $this->demoFirstTextDataConfiguration->updateConfiguration($data);

Data provider class help to load saved data from class configuration as written above.

Step 10 :

Add below line in DemoFirstTextDataConfiguration.php in From

namespace PrestaShop\Module\DemoForms\Form;
use PrestaShop\PrestaShop\Core\Configuration\DataConfigurationInterface;
use PrestaShop\PrestaShop\Core\ConfigurationInterface;

final class DemoFirstTextDataConfiguration implements DataConfigurationInterface
    private $configuration;
    public function __construct(ConfigurationInterface $configuration)
        $this->configuration = $configuration;
    public function getConfiguration(): array
        $return = [];
        if ($translatableTextArea = $this->configuration->get(static::TRANSLATABLE_TEXT_AREA)) {
            $return['translatable_text_area_type'] = $translatableTextArea;
        if ($formattedTextAreaType = $this->configuration->get(static::FORMATTED_TEXT_AREA_TYPE)) {
            $return['formatted_text_area_type'] = $formattedTextAreaType;
        return $return;
    public function updateConfiguration(array $configuration): array
            static::FORMATTED_TEXT_AREA_TYPE, $configuration['formatted_text_area_type'], 
            ['html' => true]
        return [];
    public function validateConfiguration(array $configuration): bool
        return true;

That’s all about PrestaShop data provider and handler, this is how you can use Symfony Form in Prestashop to saving data in configuration class.

If you are facing any issues or doubts in the above process, please feel free to contact us through the comment section.

I would be happy to help.

Also, you can explore our PrestaShop Development Services and a large range of quality PrestaShop Modules.

For any doubt contact us at [email protected].

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home