GSoC Week 1: encrypt_content_client - Module skeleton and .install file

Git workflow

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.

Module skeleton

Module skeletonI 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.  

Bash script

 

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:

 

Database public_key

 

Prior to that I had to research how adding new fields is carried out in Drupal 8. This video on drupalize.me and this article helped me understand how it works.

 

I will be able then to call the core API and receive newly created fields from JavaScript library that will be created next week.

REST Webservices

Then I manually enabled my fields to be visible on user’s edit page. The next step was to install REST Webservices module. This page helped me understand how REST resources are handled in Drupal 8.

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.

 

Resource config

 

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.

Interesting issues

  • 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

  • start working on a JavaScript wrapper for OpenPGPjs library
  • create a sandbox page for development and testing of my JavaScript library
  • research on JavaScript coding standards in Drupal 8 (drupalize.me)
  • expand on the API resource I have created