Zend certified PHP/Magento developer

Data persistor in the same form for edit and add new element Magento 2

I got this structure for my form:

  • route: admin/partnerportal/partner/edit
  • ui_component: partnerportal_partner_edit.xml
  • layout: partnerportal_partner_edit.xml

I use the same form to edit existing elements and to add new elements, and it works fine. However, when something goes wrong in the validation (save controller) I want to return back in the edit form with all the data/changes I made, so I used the dataPersistor. However there is a problem: for the edit part it works fine, but when I create a new element it does not work, the fields return blank.

I found the reason, that’s because the url should be admin/partnerportal/partner/edit/entity_id/value (ex. value=5), but in reality it is admin/partnerportal/edit. How can I fix that?