Drupal8 Development Standards
Total Page:16
File Type:pdf, Size:1020Kb
DRUPAL8 DEVELOPMENT STANDARDS Coding Standard and Best Practices Abstract This document covers best practices to be followed by all developers who will be working on development and implementation of a Drupal8 CMS on Acquia platform for UNICEF. ICTD-Solution Center and Services Table of Contents 1 Executive summary ......................................................................................................................... 3 2 List of standardized tools which should be used while working on Drupal8 Project...................... 4 3 Creating a new Drupal8 codebase .................................................................................................. 4 4 Drupal 8 implementation structure (where do I find what) ........................................................... 5 4.1 Directory Structure ................................................................................................................ 5 4.2 Install Profile .......................................................................................................................... 5 4.3 Modules ................................................................................................................................. 5 4.4 Themes .................................................................................................................................. 6 4.5 Test directory structure ......................................................................................................... 6 5 Coding standards ............................................................................................................................ 7 6 Theme standards ............................................................................................................................ 7 7 Automated Testing .......................................................................................................................... 7 7.1 Coding standard Test ............................................................................................................. 7 7.2 Functional Test ...................................................................................................................... 7 8 Git Usage and workflow .................................................................................................................. 8 8.1 Pull Requests, commits and Code Review Guidelines ........................................................... 8 8.2 Naming Conventions when using Git .................................................................................... 9 8.3 Developer Workflow .............................................................................................................. 9 8.4 Deployment Via BLT ............................................................................................................ 10 9 Best practices for project/website development ......................................................................... 10 9.1 Composer Dependencies ..................................................................................................... 10 9.2 Configuration Management ................................................................................................ 11 9.3 Custom Code ....................................................................................................................... 11 9.4 Updates................................................................................................................................ 11 9.5 Variables naming ................................................................................................................. 11 9.6 Theme best practices ............................................................................................................................... 12 9.7 Definition of DONE during development process ............................................................... 12 10 Best practices for PR code review ............................................................................................ 12 10.1 Preparation steps ................................................................................................................ 12 10.2 General checks ..................................................................................................................... 13 10.3 JavaScript-related checks .................................................................................................... 13 10.4 Twig-related checks ............................................................................................................. 13 10.5 CSS and Sass-related checks ................................................................................................ 13 10.6 PHP-related checks .............................................................................................................. 14 10.7 YAML-related checks ........................................................................................................... 14 10.8 Automated Checks ............................................................................................................... 14 10.9 Definition of DONE during code review process ................................................................. 15 11 Resources & additional information ........................................................................................ 15 1 Executive summary The purpose of this document is to provide guidelines, recommendations and the minimum mandatory requirements, which should apply to any Drupal 8 CMS based implementation using the Acquia platform and authored by or under the responsibility of any UNICEF office. UNICEF development standards are built to ensure a coherent and cohesive Drupal 8 implementation strategy across the organization as well as better quality, robustness and maintainability during development, launch and post-launch. UNICEF development standards require the use of Acquia BLT framework with Drupal native configuration management. Using Acquia BLT enforces the development to use a set of tools, such as Composer and NPM as the dependency management tools, and a Continuous Integration tool (such as Travis). In addition, UNICEF highly recommends the use of a Drupal VM for easier integration with BLT. UNICEF requires to use configuration management approach (file-based) instead of regular SQL database storage, in order to benefit from a versioning system for configuration in any Drupal 8 implementation. In order to enable easier compliance of these standards, UNICEF will provide a Composer file, which will include the list of approved Drupal modules. This Composer file will be required to be used to create the project. In addition, UNICEF will provide a private Github repository under UNICEF Github organization account where all development should happen. Regular audits might be performed by UNICEF technical team to ensure compliance of UNICEF development standards. Additional requirements, guidelines and best practices are found in the document below. 2 List of standardized tools which should be used while working on Drupal8 Project The below list includes a (non-exhaustive) list of required and recommended tools to be used in any Drupal 8 implementation. Name of tool Description Ticketing/Project UNICEF highly recommends the use of a project tracking tool which support tracking software agile/scrum based projects (e.g. VSTS, Github Issues, JIRA) tool Github UNICEF requires the use of Github as the control versioning tool. Acquia BLT UNICEF requires the use of Acquia BLT for deployment, build and test. Continuous UNICEF highly recommends the use of Travis CI for seamless integration with Integration Acquia BLT. Bootstrap UNICEF requires the use of Bootstrap as the base theme Acquia Lightning UNICEF requires the use of Acquia lightning distribution profile. distribution 3 Creating a new Drupal8 codebase UNICEF requires to use composer to manage dependencies with the codebase. For creating a new Drupal8 codebase, UNICEF will provide composer files. Any deviation from the included core and contributed modules and versions will have to communicated/coordinated with UNICEF development team for approval before implementation. Please note that UNICEF composer includes Acquia BLT framework to manage and deploy code and database, as well as Acquia lightning distribution and additional contributed modules those are approved by UNICEF. UNICEF standards highly recommends the use of Drupal VM, as it provides a self contained environment for local development. More information is found at https://www.drupalvm.com/ UNICEF standards requires the use of Drupal native configuration management approach (file- based), as it provides a versioning system for configuration instead of regular SQL database storage. More information on configuration management is found at https://www.drupal.org/docs/8/configuration-management 4 Drupal 8 implementation structure (where do I find what) This section describes the required implementation architecture structure that should be followed: 4.1 Directory Structure Top-Level directories /blt /config /docroot /composer.json /travis.yml Second-level directories /docroot/modules/ /docroot/profiles/ /docroot/sites/ /docroot/themes/ 4.2 Install Profile Install profile in Drupal 8 has all the functionality of modules, including access to hooks and plugins and, critically, the ability to provide configuration for the site in the form of .yml files. The profile name should consist of lowercase