GSoC’17 Coding period | Week #2 | Drupal

week2

 

Google Summer of Code 2017 has entered yet another week and with the conclusion of week 2 of the Coding Phase, things in general have become much more elaborative, as well as exciting !

The previous week was significantly noteworthy in terms of the intricacies and topics dealt with for the  objectives undertaken for the first phase. I was also able to manage time better to focus more towards my project, and the implementation in particular. In the previous blogpost, I had mentioned about the port objectives decided with regard to the first phase of the coding regime. As planned earlier, my main intent for the week was to port the functionality ‘Add administrator wish list settings’. The port of this sub-module encapsulated the completion of the following objectives:

  • Configuring the wish list settings by administrator: This feature allows the administrator to implement crucial settings related to any wish list for authenticated users. 
  • Managing user wish lists: This feature enables the administrator to keep track of the wish lists created by authenticated users and implement changes if necessary.

Thus, briefly explaining the steps taken to port the administrator wish lists settings under this week’s regime:

  • Creating the Form Controller:
    • The first step is to create the actual form, by creating a file called UcWishlistConfigForm.php and place it as src/form/UcWishlistConfigForm.php.In this php file we define a class called UcWishlistConfigForm that extends ConfigFormBase.

    • We give the form a unique id by creating a getFormId() method and returning a unique form ID as a string.

    • To build the actual form, we add a method called buildForm() and define the form elements (using Form API) in this method.

    • Since the form is incomplete without a submit button, we add a method called submitForm() that will be used to save the form values.

  • Building Route and Menu items:

    • For the form controller we need to make it accessible via a menu in Drupal’s admin section, by defining a route in uc_wishlist.routing.yml and a menu item for the route in uc_wishlist.module files and placing them in the module’s root directory.
  • Defining configuration settings:

    • For storing the actual form values, D8 comes with a Configuration System that stores site configuration directly on the file system using YAML files and not in the database.

    • Created a uc_wishlist.settings.yml file and placed it in a folder called config from within the module root directory. The path to the YAML should end up being config/uc_wishlist.settings.yml.

Administrator wish list settings in Drupal 8 after port:

adminis

 

As stated above, I was able to port the ‘administrator wish list settings’ successfully this week through the above mentioned procedure, and the code associated with the port can be found here. Also, the related bugs associated with the port of he sub-module would be reported/fixed as scheduled. I further plan to complete the port of the first sub-module by integrating the functionality to manage the user wish lists in Drupal 8. Furthermore, I also intend to complete a fair part of the next sub-module by porting 'Add to wish list' and 'Add to cart' system functionalities.

Also I came across few crucial facets regarding the differences in the Configuration Management System in D8, which is listed as follows:

  • The Drupal variables are replaced by the Configuration API. We need to define the properties and default values in the new format.

  • In D7 we define your form arrays in functions and in D8 we create a form class.

  • In D7 the form values are usually stored in the ‘variable’ table and retrieved by using the variable_get('name') API function, but D8 involves storing them in YAML files.

Summing up, these were some of the objectives and concepts learned during the second week of coding phase in GSoC’17. Hope to learn many more new concepts in the coming weeks for successful completion of the port.

Cheers!