We’ve heard that developing with Drupal 8 is fast by default, but does that extend to your development process? There are new tools in Drupal 8 that can accelerate your day-to-day work, and will help you master rapid development in Drupal 8.
Join Myplanet’s Erin Marchak as she does a live walk through of building a site install with Composer, developing a module with Drupal Console, and ingesting external content with Services, all within 1 hour. In this demonstration of Drupal 8’s improved developer experience, topics covered will include
Dependency management using Composer
Content ingestion using Guzzle PHP
Code scaffolding using Drupal Console
Configuration management using Drupal Console
Drupal 8’s Services and Dependency Injection
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console and Services
1. Fast Paced
Drupal 8
Speed up with composer, console and services
/@emarchak @myplanetHQ
/emarchak.github.io/fastpaced_drupal8 github.com/emarchak/fastpaced_videos
4. Why Change for D8?
1. Speed up your development process
2. Play well with others
5. Dependencies
Dependency manager for PHP
Extends Symfony console for boilerplates and interactions.
Guzzle is a PHP HTTP client.
Familiarity with Drupal 7 development
Composer
Drupal Console
Guzzle (in core)
6. Overview
1. Build using Composer
2. Install using Console
3. Create a Module using Console
4. Export Content Types using Console
5. Create Admin Form using Console
6. Create a Service using Console
7. Import Nodes using Guzzle
8. Include your module using Composer
8. 1. Build using Composer
Download Drupal into the docroot.
to Drush Make for building sites.Composer is a really exciting alternative
$composercreate-projectdrupal/drupaldocroot8.0.5
$cddocroot
9. Managing patches using composer
For Drupal 8.0.5 only, we'll need to , but any module can be patched.patch core
$composerrequirecweagans/composer-patches--no-update
"extra":{...
"patches":{
"drupal/drupal":{
"Combinationof--prefer-distand.gitattributesconfusesourvendortestcleanup"
}
}
10. Add to installer paths to let us download modules to
./docroot/modules/contrib
"extra":{...
"installer-paths":{
"modules/contrib/{$name}":[
"type:drupal-module"
]
}
},
11. Add as a repo,
so we can download Drupal modules.
Drupal Composer
"repositories":[{
"type":"composer",
"url":"https://packagist.drupal-composer.org"
}]
12. Install some Drupal modules!
improves the core Drupal toolbar,
and is used in our demo.
Admin Toolbar
Video Embed Field
$composerrequiredrupal/admin_toolbar:8.1.14--no-update
$composerrequiredrupal/video_embed_field:8.1.0-rc5--no-update
$composerupdate
13. 2. Install using Console
$drupalsite:install
$drupalmodule:installadmin_toolbar
$drupalmodule:installvideo_embed_field
14. Move the configuration sync directory outside of the docroot,
and add .Symfony's new trusted host patterns
$config_directories['sync']='../config/sync';
$settings['trusted_host_patterns']=['^fastpaced.local$'];
$drupalconfig:export
15. 3. Create a Module using Console
Let's create a fast-paced module...
$drupalgenerate:module
Enterthenewmodulename:
>Fastpacedvideos
16. ... and a speedy content type!
$drupalgenerate:entity:bundle
Enterthemodulename[admin_toolbar]:
>fastpaced_videos
Enterthemachinenameofyournewcontenttype[default]:
>video
$drupalmodule:installfastpaced_videos
17. 4. Export Content Types using Console
Log into the site and configure the content type as needed,
before you export it.
$drupalconfig:export:content:type
>video
Exportcontenttypeinmoduleasanoptionalconfiguration(yes/no)[yes]:
>no
18. Can we generate some example content? Yes we can.
$drupalcreate:nodes
19. 5. Create Admin form using Console
$drupalgenerate:form:config
EntertheFormClassname[DefaultForm]:
>ImportSettingsForm
Doyouwanttogenerateaformstructure?(yes/no)[yes]:
>y
Type: number
Inputlabel: ImportMax
Description: Maximumamountofnodestoimportprecronrun
Defaultvalue:10
Type: textfield
Inputlabel: SearchTerms
Description: Feedtoimportfrom
Defaultvalue:macaframa
20. Export the configuration settings.
$drupalconfig:export:single--directory=modules/custom/fastpaced_videos/config/install
Configurationtype[Simpleconfiguration]:
>system.simple
Configurationname[automated_cron.settings]:
>fastpaced_videos.importsettings
21. 6. Import Nodes using Guzzle
Add fastpaced_videos_cron().
/**
*@file
*Containsfastpaced_videos.module.
*/
useDrupalCoreUrl;
useDrupalComponentSerializationJson;
/**
*Implementshook_cron().
*/
functionfastpaced_videos_cron(){...}
Some parts of Drupal 8 are still procedural like 7,
hook_themeand hook_cron, for example.
for further changes to fastpaced_videos.moduleRefer to the repo
22. 7. Create a Service using Console
We'll be importing videos using guzzle, so we'll need to create
a service to save them.
$drupalgenerate:service
Entertheservicename[fastpaced_videos.default]:
>fastpaced_videos.import
EntertheClassname[DefaultService]:
>ImportService
Doyouwanttoloadservicesfromthecontainer(yes/no)[no]:
>yes
Enteryourservice[]:
>entity.query
>entity_type.manager
for further changes to fastpaced_videos/src/ImportServiceInterface.phpRefer to the repo
23. 8. Add your custom module to composer
Add as a repo,
so we can can download our custom module.
our github repo
"repositories":[...{
"type":"git",
"url":"https://github.com/emarchak/fastpaced_videos.git"
}]
$composerrequireemarchak/fastpaced_videos
24. Ride eternal, shiny and chrome.
/@emarchak @myplanetHQ
/emarchak.github.io/fastpaced_drupal8 github.com/emarchak/fastpaced_videos