I'm new in Magento 2 and I couldn't figure out what is the difference in doing a admin form module in PHP, calling a class and then using formFactory to create the form:

<referenceContainer name="content">
            <block class="BVZ\Designer\Block\Adminhtml\Post\Edit" name="designer_post_edit"/>


$form = $this->_formFactory->create(
                'data' => [
                    'id' => 'edit_form',
                    'action' => $this->getData('action'),
                    'method' => 'post',
                    'enctype' => 'multipart/form-data'

or calling a Ui component and using a xml fieldset

        <referenceContainer name="content">
            <uiComponent name="stores_index_edit"/>


<field name="store_id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">false</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">store</item>

Is it a method better than the other or it has different proposals?


These are the difference :

FormFactory and XML :

  • Easy to debug.
  • Relatively easy to build non-standard grids.
  • You got full control of what happens.
  • You can use your knowledge from M1 to do it.
  • Grid is not that flexible or extensible.
  • you need to write the same code over and over again.
  • More code to test or that can break

Ui Components

  • Difficult to debug

  • Difficult to build non standard grids

  • It's mostly configuration. So you write less code, so less code that can break

  • you get a cool grid with show/hide columns, full text search, inline edit, export built in and maybe others.

  • It can easily be extended with just another xml file in a different module

  • any new feature magento rolls out for the grids you will get it automatically in your grid.

  • Not very much control over what happens

    I suggest you to use ui-components instead of FormFactory.

  • Nice answer! So you suggest using Ui-components because its easier and less code, but what is the threshold of controll with this method? Do you have any pattern to follow when building a Magento 2 module? I didn't find a lot of good documentation and patterns. – Arthur lauck do nascimento Jun 20 '18 at 13:39
  • It's really knowledgeable, thanks mate !! – Aditya Shah Jun 21 '18 at 5:57
  • @Arthurlauckdonascimento here are the full documentation of UI-component provided by magento devdocs.magento.com/guides/v2.2/ui_comp_guide/bk-ui_comps.html – Chirag Patel Jun 21 '18 at 6:05
  • @ChiragPatel In my opinion magento 2 is very poorly documentated, but for sure, you helped a lot! It's a nice to know that Magento 2 has a good communite. – Arthur lauck do nascimento Jun 21 '18 at 11:27

According to DevDocs :

UI Component are designed for simple and flexible user interface (UI) rendering. Components are responsible for rendering result page fragments and providing/supporting further interactions of JavaScript components and server.

Basicly UI componet is combination of XML and JS, we configur page using XML Declaration and it uses Magneot JS class like UIElement, UIClass or UICollection. It may use phtml templates.

You can check this working example(Magento-2-custom-module-CRUD) for create model and CRUD operation using UI Component fORM and GRID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.