Magento 2 – Use UI Form Component Without Data Source

magento2uicomponent

  • I wish to create a form in admin.
  • The purpose of the form is not CRUD.
  • Using blocks for creating forms is marked as deprecated in favor of ui_component forms
  • Is it possible to use a ui component form without a data source?

Best Answer

From my digging it turns out the data provider is required.

I just implemented a dummy data provider.

class Form extends \Magento\Ui\DataProvider\AbstractDataProvider
{
    /**
     * Get data
     *
     * @return array
     */
    public function getData()
    {
        return [];
    }

    public function addFilter(\Magento\Framework\Api\Filter $filter)
    {
        return;
    }
}

I had to override both methods that work with $collection member to avoid errors.