I would like to start this update post by talking about the Git workflow that I will follow. I have created issues for each of the objectives that I agreed on with my mentor. I then automatically create a branch and merge when I test so that it works and covers tasks described on the issue’s page.
My mentor suggested that we have weekly code reviews on Monday, a day before meetings on Tuesday.
I started the coding period by creating a module’s scaffolding using drupal console command. The command created basic files that provide information about the module.
I have also created a config file that will store global settings for the module, the file is called encrypt_content_client.config.yml.
I also have found this useful Drupal console cheat sheet.
Module install file
After talking to my mentor I changed my approach a bit. PGP keys will still be stored in the database, but I will add fields to the user entity instead of creating a REST resource and managing key additions using my own functions. Then I can still retrieve them using my own REST resource that retrieves each user’s attributes.
I used the Examples project to get an idea about scaffolding for particular files.
For quicker development I used two commands from Drupal console and I created a bash script that executes them, doing that helped me test changes to the module quicker.
Add fields to user entity
As I was advised by Colan to go with a simpler approach of extending the user entity on module’s install I proceed to do that and ended up with public_key and private_key fields along with tables in the database:
I downloaded REST UI module in order to edit settings for REST resources. I have also created my own resource along with a config file so it’s enabled on module’s install.
Making a GET call to /pgp/1/public?_format=json with cookie authentication returns PGP keys for either selected or all available users.
Define OpenPGPjs library
The core library that will be the base of my module is OpenPGPjs. The next step is to create my wrapper for the library that will be loaded as well as the main library into Drupal.
I have also generated a PGP key pair and shared it on the Gitlab repository page so it can be used in development as the main key pair.
- configuration objects (core.entity_form_display.user.user.default [...]) already exists in active configuration
I was following this tutorial. And I have my field.field.user.user.* and field.storage.user.* files and the and then I created core.entity_view_display.user.user - and when I tried to reinstall the module I got above error. I did not check that this tutorial was only for custom content types, files I tried to create for user already existed in the code - lesson learned!
I learned about active config and that I need to pay attention to some settings may be left from my previous module installation if not handled properly on uninstall.
- [...] has unmet dependencies
I did not include field module dependency in my module when adding custom field to user entity. I make sure it’s installed on a new Drupal installation before I can install my module. Drupal console is really helpful as it installs any module dependencies listed in .install file.
Plans for week 2
- expand on the API resource I have created