[Drupal Custom Module] Drupal add ANY data/field to display

Suowei Hu
Sep 26, 2023

--

STEP-1
First you will need to make modification to file “modules/custom/framework_modules/framework_modules.views.inc”, which will add view data (Global field) to the view “framework_modules”, the changes made is shown as the follows, the example is showcasing how to add “update time” for module 1:

(More detail please see drupal documentation on: https://api.drupal.org/api/drupal/core%21modules%21views%21views.views.inc/10.0.x)
(More detail please see drupal documentation on: https://api.drupal.org/api/drupal/core%21modules%21views%21views.views.inc/10.0.x)

STEP-2
Then you will need to have create the corresponding data source at folder “modules/custom/framework_modules/src/Plugin/views/field” (the exact filename of the php does not matter, as long as you are matching the “@ViewsField” with the data id using earlier in step-1, it will work no issue), here we will use “FrameworkModulesUserModuleOneDate.php”, the logic and important positions of the source code have been labeled and displayed as the following:

STEP-3
Then you will need to perform a cache clear, then add this new field to the corresponding display, and see it taking effect:

--

--

Suowei Hu
Suowei Hu

Written by Suowei Hu

Drupal Developer, createing impactful solutions. | Student at Australian National University, an enthusiastic learner. | Github: https://github.com/SuoweiHu

No responses yet