Override Form Using Plugin

ankur.porwal
ankur.porwal Spryker Solution Partner Posts: 10 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

Hello Team,

I want to add new field in this from class "/vendor/spryker/product-attribute-gui/src/Spryker/Zed/ProductAttributeGui/Communication/Form/AttributeForm.php" using plugin concept.

Tell me the steps how can we achive this?

Comments

  • Hidran Arias
    Hidran Arias Senior Technical Trainer Sprykee Posts: 81 ๐Ÿ› - Council (mod)
    edited May 23

    Hi Ankur,

    We have course on how to extend core packages and one form example. https://spryker.sana.ai/s/WT9Vuc2q5Sue/file%3Aj3LpSxvifehU

    You'd have to extend the form factory at project level and create a new form also at project level which extends the core form template.

    Then, the project factory would return an instance of the new form instead of the core one

    Spryker would automatically load your project factory instead of the core one if you follow Srpyker's naming conventions for overriding Factories, facades, Config and providers

  • ankur.porwal
    ankur.porwal Spryker Solution Partner Posts: 10 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    Hello @Hidran Arias,
    I know this way which is mentioned in the document but We want to try some different way because we want to create our custom module in this module we want to override the same form class in our module using any plugin/dependancy like.
    I got one file "/src/Pyz/Zed/Form/FormDependencyProvider.php".

    But we are trying to check the example of the file but we are not able to get any suitable example.

    Any help would be appriciated!

  • Hidran Arias
    Hidran Arias Senior Technical Trainer Sprykee Posts: 81 ๐Ÿ› - Council (mod)

    I took a look at the ProductAttributeFormGui but there isn't any plugin you can hook into for that form.

    The form is created in the factory:

    public function createAttributeForm(array $data = [], array $options = [])

    {
    
    return $this->getFormFactory()->create(AttributeForm::class, $data, $options);
    
    }
    
    So, they only way to add a new field would be to override that factory method at project level, extend that form and add the new field. This has to be created with the same module's name otherwise it won't be auto discoverable.