Backend (Level 2)
Drupal Onboarding project tasks used for learning
Cache API overview
To get basic understanding of how caching works in Drupal 8, check this video: https://www.youtube.com/watch?v=MQGUzubY35I
While watching the video, simulate the examples on your page to see the difference.
Caching for Site status message
This task is an upgrade of 'Configuration form (Site status message module)', so you have to finish that one first.
Since the messages in Site status are are usually quite static, we want to make sure they are cached. We only want the caches to get invalidated on a configuration change of Site status module.
Favorites count block (+ Cache API)
This task is connected to "Add to favourites on Event page" task. If you haven't finished that one, do that first.
Our goal here is to create a custom block which will output the number of items user has added to favorites. This block will then be shown in a page header for logged in user, click on it will take you to the page (My favorite events).
The point here is, that we have to make sure, that on each change, this block will be updated and not showing the old cached value. So on next refresh, we must have the updated value. It's not enough that you only use cache max_age, you have to be more sophisticated, using cache tags and cache contexts.
At the end, you also try to figure out how would you update the value in the block as soon as you add/remove an item from favorites. Now you have to refresh the page to get the new value in block.
Permissions and creating custom permission
This task is an upgrade of 'Configuration form (Site status message module)', so you have to finish that one first.
We would now like to select which roles can edit the configurations for Site status message. To make this work, first define a permission (let's call it 'Administer site status message') and then assign this permission to all authenticated users.
Later on, create a new role called Editor (if you don't have it already). We don't want all authenticated users to administer site status message, so add this permission only to users with role Editor. Additionally, those users should also be able to add and edit Events, Locations and Companies.
Login with social network account
We want to make our visitors an option to register and login with their Google or Github account.
First do a review and check out what modules do you have available and talk to your mentor which would you choose.
Afterwards configure two providers mentioned above. The end result must be three different options on login/register screen - regular Drupal login, Google and Github.
Equipment scoring
Client wants to display 1-5 stars rating on the Location page, using the values from equipment. For example: if they have parking and wi-fi, but no air-conditioning, they get 3 stars, if they have air-condition as well, they get 4 stars etc. The equipment and ranking is something you can make up. Out of your equipment items (let's say you must have at least 5 of them) create a scoring system, that will represent the number of stars.
Think about the possible solution and discuss this with your mentor, before you start coding.
After that, display number of stars on each Location node, depending on the equipment that each location has. Prepare two different displays: a block, that you can put in a region, and a pseudo-field, that will be available in Manage display.
When you'll create a block, also use a custom twig template for it, so others will have an option to override it.
Search API & Facets
Install Search API module and create new list pages which will be using Search API for displaying results (eg. /companies-searchapi, /locations-searchapi and /events-searchapi).
After you're done, install Facets module and create facets for each search page and add them on page. You can create facets for taxonomy on each content type, or you can add some other field as well.
The final task is to create your own field in search index which will be displayed as facet. This field will be for a list of companies and should have a name "Has events". Each company that has at least one event assigned to it, will display on the results, when the user will check the option in facet.
Additionally, update that to 'Has upcoming events', so only the companies who have events that are in future will show up.
Solr
Enable Solr in your environment (should be DDEV, but aslo Docksla, Lando and other tools, have a built in support) and change search server on list pages you created in previous tasks (Search API & Facets) to Solr server.
If you're using DrupalVM, DDev, Lando or any other tool that has a pre-built configuration, then you usually just have to uncomment or add configuration for Solr and provision virtual machine/docker.
Cron job
Related to 'Search API & Facets' task, so finish that first.
'Has upcoming events' filter can change on daily basis. If one company has future events today, they might not have any more next week. So we have to take care, that reindex is triggered on regular basis.
Create a cron job that will take care of this and reindex affected items at least once per day.
Create drush command
Related to 'Search API & Facets' task, so finish that first.
Beside the cron job you made in previous task, now create Drush command for the same task as well. We will use it when we want to manually run the reindex of companies.
There are multiple versions of Drush available, but since Drupal 8.2 only Drupal 9+ is supported, so we'll focus on that.
Links:
Module: Message
We will create a system with which users will be able to get notifications on the page about new events (similar to Facebook notifications system). We will use Message module.
First, create 'Notify me about new events' field on user profile. When new event is added, every user that has this option checked should receive a notification. The notifications text should be: New event [event_title] has been added and will take place at [event_start_date] in [event_location].
Create a View block and place it on user page (you can call it My notifications). This will be a list of all the notifications for that user. Make sure, that we don't show the notifications for events that are already passed. We have an additional feature, that the user can select the maximum number of items that are shown in this block. The setting should be in user profile and should be taken into the account when preparing view. Create two blocks with two different approaches: with a Views block and also as a block plugin in custom code. The final output should be the same for both so it's best if we use the same view mode in views and in code.
After you're done with this, upgrade the functionality. Create additional field on user profile which will have the same categories as Events do (Event type). Now user will be able to select which event types are of his or her interest. Now, users should only get notifications for events of type they selected.
Hint for dynamically changing the number of results in Views: hook_views_query_alter.
Migrate content (csv)
Migrate content to Drupal. Create a simple csv file, that has fields needed for creating a company. Create couple of lines in that csv and import them in Drupal.
- https://www.drupal.org/docs/8/api/migrate-api/migrate-api-overview
- https://drupalize.me/series/drupal-8-migration-guide
- https://www.drupal.org/docs/8/modules/migrate-source-csv/using-the-migrate-source-csv-plugin
- https://evolvingweb.ca/blog/drupal-8-migration-migrating-files-images-part-3 // for images