When I deployed a Blog module in a Magento 2 Shop, I was wondering why It didn’t populated all the shown fields in the corresponding backend Admin View. Namely the
Modified At and the
Custom Date field were showing blank values, despite having valid values in the database.
Short side note: The
Custom Date Field was added manually as the name may be imply – See here for a how-to. But now back to the topic:
This article will present a summary of a successful method to bring back the correct values to the empty UI Component Fields.
Looking for Bugs and Mistakes
The first place where to look for the issue is the place where the actual fields are defined. Namely the responsible XML File. In my case that is:
In Line 20 you can see the DataProvider class
PostGridDataProvider being defined. Following the rabbit-hole the
/app/code/EeroKaan/Blog/etc/di.xml File tells us, what the
PostGridDataProvider class actually is:
Line 60 links the
PostGridDataProvider to the
EeroKaan\Blog\Ui\DataProvider\Post\PostDataProvider class. Inside of the
PostDataProvider class under the
/app/code/EeroKaan/Blog/Ui/DataProvider/Post/PostDataProvider.php path, we can see a certain
getData() Method. By inserting a
print_r( $items ) after the initialisation of the collection we can output the collection array itself.
As you can see from the data the array holds, the Admin view doesn’t have any chance to display the requested data, since it’s not present. The fields
eero_custom_date are missing. To add them to the array anyways we can now proceed with the actual solution.
Fix the Code in the Right Place
To add the missing fields to the collection, we utilize the simple
addField() Method in the Class Constructor like so:
Then checking again with the
Since the necessary fields are now present, the Admin UI Component is now able to display our field values:
And there you have it: Thats how I was able to finally implement the missing values in my Magento 2 Admin View. Hopefully this way is also applicable to your case.