Today is my last day of work with the Robertson Library RDM team. I have learned a lot during my time here. I will talk about some of the things that I once struggled with but eventually figured out.
1. Chart.js in Disk Usage Module
We wanted to display a report of the disk storage used by Islandora 8 repository items, so I created the Disk Usage Module. I used Chart.js in my code to display a pie chart and a bar chart. I didn’t know anything about Chart.js but luckily it is well documented, so it was very easy for me to learn and find examples on it's website (https://www.chartjs.org/docs/latest/). What’s more, an example of a bar graph in the README.txt file of chartjs_api was especially helpful. Here is my code of creating the charts:
//Create a chart with the entities. Using the ChartJS API module.
private function createChart($chartType, $groupBy) {
...
$report = [
'#data' => [ ... ],
'#graph_type' => $chartType,
...
'#type' => 'chartjs_api',
];
return $report;
}
2. Solr Search Service
Solr Search is to show the search results and individual node on the RDM site. It has several components such as facets, dataset title, and an access rights symbol. We don’t create html directly in the PHP code, instead, we use custom twig templates. The steps of creating templates are documented on the Drupal site (https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-for-custom-module), but I’ll add an additional example which is slightly different from the one on the site.
The first step is the same, I first hooked the theme in islandora_rdm .module file, I then added a preprocess function to get the abstract description and put it in a variable. The description will not be displayed if its type isn’t “abstract”. Here is the code:
function islandora_rdm_search_result_preprocess(&$variables) {
foreach ($variables['node']->get('field_rdm_description')->referencedEntities() as $description) {
$type = $description->get('field_rdm_description_type')->getString();
$abs_description = $description->get('field_rdm_description')->getString();
if ($type == 'Abstract'&& trim($abs_description) != "") {
$variables['rdm_abstract'] = "Abstract: " . $abs_description;
}
}
}
In the twig file:
<p>{{ rdm_abstract }}</p>
Secondly, I made a twig file node--islandora-rdm-dataset--search-result.html to display the results. I didn’t call it myself since the Views module in Drupal core will do that automatically.
My final step was to create a CSS file search-result.css because I needed to make some adjustments on the page. I then added the file to islandora_rdm.libraries.yml:
search:
version: 1.0
css:
layout:
css/search-result.css: {}
3. Some tools I used:
We use Git to manage our code. During my time at RDM, I learned how to debug with the error log, how to clean up code with PHP CodeSniffer, how to synchronize code from the server and NetBeans IDE, how to make a new repo on Git, and how to push and pull from Git.
I didn’t realize Drupal was such a powerful framework until I actually worked with it. It takes some time to learn but it is worth it. I had a great time working with RDM team and I hope to work with them again in the future.