Learning tasks for Developers¶
Useful guides, resources and code examples to learn software usage that is required for this project.
Useful 8.x cheatsheets¶
Suggested Drupal 8.x books for advanced developers.
- Enterprise Drupal 8 Development
- Drupal 8 Development Cookbook
- Drupal 8 Blueprints
- Programmer’s Guide to Drupal, 2nd Edition
- High Performance Drupal
- Drupal Watchdog magazine
Drupal 8.x supports (and promotes) usage of Composer. Core and contrib projects may require external libraries that can be attached to the Drupal app using composer.
Composer can install libraries from Packagist - The PHP Package Repository as also as any other package hub that supports composer.
- See Common Problems and Solutions with Drupal + Composer
- Learn more about composer commands online or by running:
// Show available composer commands composer list
- Common composer commands for a PHP project are:
// Creates a basic composer.json file in current directory. composer init // Installs the project dependencies from the composer.lock file if present, // or falls back on the composer.json. composer install // Adds required packages to your composer.json and installs them. composer require // Updates your dependencies to the latest version according to composer.json, // and updates the composer.lock file. composer update // Removes a package from the require or require-dev. composer remove // Dumps the autoloader composer dump-autoload // Create new project from a package into given directory. composer create-project // Validate a composer json composer validate // Show the installed packages composer show --installed // Show details about a package composer show doctrine/annotations // Check that there is a newer version available composer show -a "drupal/core" // Check why composer won't install something composer why-not "drupal/core:8.3.6" // Check if we have a version of 'php/reflection' in our lock file that is too high for another package composer why "php/reflection"
- Example of adding requirements of the address module:
// Go to the Drupal root cd <APP_ROOT> // Add the requirements abd update composer.json composer require commerceguys/intl composer require commerceguys/addressing composer require commerceguys/zone
- Example of a Drupal build made by composer:
// Set the source of Drupal packages composer config repositories.drupal composer https://packagist.drupal-composer.org // Download drupalcommerce/project-base composer create-project drupalcommerce/project-base <PROJECT_FOLDER> --stability dev
Building with Features¶
This is an example of a workflow using Features and Core Configuration Management (CMI) in D8. It assumes that you are using 3 development environments Development, Staging and Production.
Creating initial config:
- Use Features to organize your config into modules
- Push feature module code into git repo
- On Staging server pull the repo, enable all the modules. Initial config will be loaded
- On Staging, use CMI to export all config
- Pull both code and config export to production
- On Production, import all config
Making a change to Feature(s):
- On your Development, update the feature code, push to your repo
- On Staging, pull the code and import/revert the feature
- Once tested, use CMI to export all config
- On Production, pull code and config
- On Production, import all config
Create a multilingual website¶
Create a multilingual installation with Dummy content and inspect the database.
Use this distro: drupal.org/project/multilingual_demo
Play with git and VCS¶
Git essentials and how git works:¶
- Video: Essentials of Git: A Journey into the Sixth Dimension
- Video: Introduction to Git with Scott Chacon of GitHub
Useful git cheatsheets:¶
- Official git reference
- training.github.com, github-git-cheat-sheet
- git-tower, git-cheat-sheet
- Advanced git cheat-sheet
Interactive tools to learn git commands and terminology:¶
- Visual git cheat-sheet
- Learn git in 15 minutes
- Learn git branching
- Git How To_ Guided Git Tutorial, step by step
CLI tools (shortcuts) you can (should) use:¶
- git-flow. A method as also as a collection of commands for successful git branching and development.
- (Optional) git hub. A tool to help create pull requests, compare commits, view issues and make your life on GH better.
- (Optional) git extras. Some useful git aliases/wrappers for humans (summary, undo, ignore, changelog etc).
GUI Clients you can use.¶
Git GUI clients are mostly used to see visual graphs of the commits, to solve conflicts, to browse repos etc.
Rewriting git history¶
Many times, when working with Git, you may want to revise your commit history for some reason.
This can involve changing the order of the commits, changing messages or modifying files in a commit, squashing together or splitting apart commits, or removing commits entirely – all before you share your work with others.
Rewriting git history may cause unpredictable issues and really big headaches so here are some useful manuals you should read before going on as also as a decision diagram that helps you decide what to do.
See the online docs. Here are some basic information.
To configure git globally run
git config --global --edit
- Enable rerere
- Do not let git to auto-convert CRLF line endings into LF (
- Do not track filemode
- Use the
Example of a global
.gitconfig file (part of):
[core] autocrlf = false safecrlf = false ignorecase = false editor = /usr/bin/subl -n -w filemode = false [push] default = simple [branch] autosetuprebase = always [diff] renames = copies [color] ui = true [rerere] enabled = true autoupdate = true [merge] tool = <YOUR_GIT_DIFF_GUI>
- Debugging Drupal 8 - Videos
- Debugging During Development in Drupal 8
- Debugging Drupal 8 with Drupal Console
- You can always simulate a drush command without executing by adding the
--simulateargument at the end.
You can debug a drush command using the
drush core-status. Example:
drush st --full
- drush core-cli. Example:
- drush sql-cli. Example:
- drush watchdog-show. Example:
drush ws --tail --extended
- drush pm-projectinfo. Example:
drush pmpi --format=table
- drush pm-list. Example:
drush pml --type=module --format=table --no-core --status=enabled
- drush pm-releases. Example:
drush rl --format=table drupal
- drush config-list. Example:
drush cli system --format=list | grep article
- drush config-get. Example:
drush cget system.site --format=yaml
- drush field-info (Not ready at the moment. Please check this issue)
- drush features-status
- drush php-eval. Example:
drush ev "node_access_rebuild()"
- drush entity-updates. Example:
- drupal site:mode dev
- drupal config:debug
- drupal container:debug
- drupal cron:debug
- drupal database:log:debug
- drupal database:table:debug
- drupal module:debug
- drupal rest:debug
- drupal router:debug
- drupal settings:debug
- drupal site:debug
- drupal state:debug
- drupal test:debug
- drupal theme:debug
- drupal update:debug
- drupal user:debug
- drupal views:debug
PHP debug and testing
Drupal console commands:
- drupal database:connect
- drupal database:client
- drupal database:table:debug
- drupal database:log:debug
Code review (for Drupal)
- Drupal Development using PhpStorm
- Phpstorm - Preparing for Drupal Development in PhpStorm
- Phpstorm - Drupal-Specific Coding Assistance
- Setting up PhpStorm for Drupal”s Coding Standards
Drupal 8.x configuration system¶
Here are some facts about the new Drupal 8.x core configuration (“config.”) system.
- Config. is made to work for deployment not for packaging.
- All modules, themes and distributions (Drupal projects) have the same type of configuration (under
<project_name>/config/installhas the required config.
<project_name>/config/optionalhas the optional config. (may not be installed).
- Configuration files are of yml type.
- A config. file name should be unique.
- Config. is a group of key-value data.
- Configuration is decoupled from modules after installation. After installation the Drupal system “owns” the configuration.
- There are 2 types of config. storage: Active (currently used from the website) and Staging.
- We can have multiple config. stores (not only 2).
- Active storage is stored on the database by default.
- Active storage on the database is using UUIDs for each configuration setting.
- The tables that are created on the database are
- By default Drupal creates the Staging folder inside the public files folder.
- We can override the paths for the config. storage (usually on
- All config. is tracked by default.
- Diff. is availble to inspect the changes.
- Config. is saved per content entity.
- Config. can be individually imported/exported.
- Config. synchronization requires all files to be present (missing config. files or settings will delete the configuration!)
- Core config. system is working for the same only Drupal installation.
- Exported config. files with UUID cannot be reused on another installation.
- Always use the Config. API to export/import config. Do not edit files or database entries manually.
- We can “override” a config. setting on the fly in the settings.php file.
- We can see an overview (Report) of the config. changes at example.com/admin/config/development/configuration/report
- Useful modules that can export, import or manage config. are features, config_update, config_devel, config_sync, config_tools, config_share.
Drush and Drupal console commands for configuration management¶
- config (core)
|drush||config-edit||cedit||Open a config file in a text editor. Edits are imported into active configuration after closing editor.|
|drush||config-export||cex||Export configuration to a directory.|
|drush||config-get||cget||Display a config value, or a whole configuration object.|
|drush||config-import||cim||Import config from a config directory.|
|drush||config-list||cli||List config names by prefix.|
|drush||config-pull||cpull||Export and transfer config from one environment to another.|
|drush||config-set||cset||Set config value directly.|
|drush||config-merge||cm||(External plugin) Merge configuration data from two sites. See docs and source code at github.com/drush-ops/config-extra|
|drush||features-add||fa, fe||Add a config item to a feature package.|
|drush||features-components||fc||List features components.|
|drush||features-diff||fd||Show the difference between the active config and the default config stored in a feature package.|
|drush||features-export||fex, fu, fua, fu-all||Export the configuration on your site into a custom module.|
|drush||features-import-all||fra, fia, fim-all||Import module config from all installed features.|
|drush||features-list-packag||fl||Display a list of all existing features and packages available to be generated. If a package name is provided as an argument, then all of the configuration objects assigned to that package will be listed.|
|drush||features-status||fs||Display current Features settings.|
|drush||config-added-report||cra||Display a list of config items that did not come from your installed modules, themes, or install profile|
|drush||config-diff||cfd||Display line-by-line differences for one config item between your active config and the version currently being provided by an installed module, theme, or install profile|
|drush||config-different-report||crd||Display a list of config items that differ from the versions imported from your installed modules, themes, or install profile. See config-diff to show what the differences are|
|drush||config-inactive-report||cri||Display a list of optional config items from your installed modules, themes, or install profile that are not currently in your active config|
|drush||config-list-types||clt||List config types|
|drush||config-missing-report||crm||Display a list of config items from your installed modules, themes, or install profile that are not currently in your active config.|
|drush||config-devel-export||cde, cd-em||Write back configuration to module”s config/install directory. List which configuration settings you want to export in the module”s info file by listing them under “config_devel”|
|drush||config-devel-import||cdi, cd-im||Write back configuration to module”s config/install directory. List which configuration settings you want to export in the module”s info file by listing them under “config_devel”|
|drush||config-devel-import-one||cdi1, cd-i1||Write back configuration to module”s config/install directory. List which configuration settings you want to export in the module”s info file by listing them under “config_devel”|
Examples of drush commands related to configuration.
// Get config of specific yml files drush config-list | grep views // Edit a config file with an editor drush cedit views.view.content // Install partial config from a folder drush cim --partial --source=/path/to/my/install/config // Install a new site from a config folder drush si --config-dir=/path/to/my/install/config // config-merge example, see more at: // https://github.com/pantheon-systems/drush-config-workflow/blob/master/docs/git_workflow.md drush @dev config-merge @stage --git --message="Move config from @dev to @stage"
Useful browser extensions and plugins¶
OOP - how to¶
- Definitions (Namespaces, Dependency Injection, Annotations, Plugin, Factory, Interface etc)
- Best practices
- IDE in the rescue
Docker allows you to package an application with all of its dependencies into a standardized unit for software development.
Docker resources can be found at Awesome-docker, A curated list of Docker resources and projects.
You can use Docker with many ways while developing. Some common scenario usages are:
- Test git branches and/or functionality (using the UI or the Drupal testing system)
- Take backups of the system (eg get the database of the build)
- Automate Continuous Integration (CI)
- Automate Continuous Delivery (CD)
- Reproduce issues and errors and share them with the team
- Test Drupal core or contrib modules updates