Now that we have covered most of the part of admin grid. Let’s learn about forms in admin.
There are two very popular ways of creating forms in admin,
- First one will be with uiComponent, this is the recommended way of creating form.
- However in many cases, you will find that the forms are implemented with block class and widgets.
We will see both ways but in this blog I will show, how to create the form with ui-component. And in the next blog we will create the form with block class.
First of all we need to add the edit link in the grid. We have seen in the previous blog itself about how to add the link column or the action column in admin grid. Let’s quickly create the column by following previous blog’s steps.
We will have to edit view/adminhtml/ui_component/blogmanager_blog_listing.xml file to add the column,
Now we need to create class for the column, Ui/Component/Listing/Columns/EditAction.php
Now you will be able to see the edit column in admin grid like below,

And now we have to create the controller as well, Controller/Adminhtml/Manage/Edit.php
If you remember, how we created the admin grid with ui-component, then it should come automatically to you that we need to create a layout file and then we will have to create the ui-component file.
The layout file will be view/adminhtml/layout/blogmanager_manage_edit.xml based on the url,
The Form Component
Now we will create the most important file of this blog that it is the ui-component file for the form, view/adminhtml/ui_component/blogmanager_blog_editing.xml
You can notice the dataProvider tag inside dataSource tag it has class associated with it which will be responsible for providing the data for the form based on the blog id. It will get the blog id from the url based on the value in requestFieldName and primaryFieldName will be used to load the model.
We can add multiple group of fields with multiple fieldset tag. One use case you can see in the product add/edit page.
We add different fields with field tag and we can configure them as we want in the tag itself. Also please notice for the status field, how we have provided the options with option class that we created earlier.
It won’t possible or practical to explain each and every part of this xml file. And as I said earlier, most of the time you will end up copy pasting these code. If you want an in depth explanation then you can always refer to the magento’s devdoc. As of now, I found many things missing from the devdoc itself. In such case, it is always good to refer to the magento’s code which you can find under /vendor/magento of root folder.
We have created the uiComponent file but we have still have one more file to create. And that file is Model/Blog/DataProvider.php which is responsible for providing the data for the form.
The getData method will provide the data that is the model for the blog. The collection will be filtered based on the requestFieldName and primaryFieldName that we have passed in the parent’s constructor.
Now when you click on the edit link, you should see the the edit form like shown below.
