Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console and Services

  • Published on

  • View

  • Download

Embed Size (px)


<ul><li><p>Fast PacedDrupal 8</p><p>Speed up with composer, console and services / @emarchak @myplanetHQ</p><p> /</p><p></p></li><li><p>@myplanetHQ</p><p></p></li><li><p>@emarchak</p><p></p></li><li><p>Why Change for D8?1. Speed up your development process2. Play well with others</p></li><li><p>DependenciesDependency manager for PHP</p><p>Extends Symfony console for boilerplates and interactions.</p><p>Guzzle is a PHP HTTP client.</p><p>Familiarity with Drupal 7 development</p><p>Composer</p><p>Drupal Console</p><p>Guzzle (in core)</p><p></p></li><li><p>Overview1. Build using Composer2. Install using Console3. Create a Module using Console4. Export Content Types using Console5. Create Admin Form using Console6. Create a Service using Console7. Import Nodes using Guzzle8. Include your module using Composer</p></li><li><p>Witness Me!</p></li><li><p>1. Build using ComposerDownload Drupal into the docroot.</p><p> to Drush Make for building sites.Composer is a really exciting alternative</p><p>$ composer create-project drupal/drupal docroot 8.0.5 $ cd docroot</p><p></p></li><li><p>Managing patches using composerFor Drupal 8.0.5 only, we'll need to , but any module can be patched.patch core</p><p>$ composer require cweagans/composer-patches --no-update</p><p>"extra": {... "patches": { "drupal/drupal": { "Combination of --prefer-dist and .gitattributes confuses our vendor test cleanup" } }</p><p></p></li><li><p>Add to installer paths to let us download modules to./docroot/modules/contrib</p><p>"extra": {... "installer-paths": { "modules/contrib/{$name}": [ "type:drupal-module" ] } },</p></li><li><p>Add as a repo,so we can download Drupal modules.</p><p>Drupal Composer</p><p>"repositories": [ { "type": "composer", "url": "" } ]</p><p></p></li><li><p>Install some Drupal modules! improves the core Drupal toolbar, </p><p>and is used in our demo.Admin Toolbar</p><p>Video Embed Field</p><p>$ composer require drupal/admin_toolbar:8.1.14 --no-update $ composer require drupal/video_embed_field:8.1.0-rc5 --no-update $ composer update</p><p></p></li><li><p>2. Install using Console$ drupal site:install $ drupal module:install admin_toolbar $ drupal module:install video_embed_field</p></li><li><p>Move the configuration sync directory outside of the docroot,and add .Symfony's new trusted host patterns</p><p>$config_directories['sync'] = '../config/sync'; $settings['trusted_host_patterns'] = [ 'fastpaced.local$' ];</p><p>$ drupal config:export</p><p></p></li><li><p>3. Create a Module using ConsoleLet's create a fast-paced module...</p><p>$ drupal generate:module Enter the new module name: &gt; Fastpaced videos</p></li><li><p>... and a speedy content type!$ drupal generate:entity:bundle Enter the module name [admin_toolbar]: &gt; fastpaced_videos Enter the machine name of your new content type [default]: &gt; video $ drupal module:install fastpaced_videos</p></li><li><p>4. Export Content Types using ConsoleLog into the site and configure the content type as needed,</p><p>before you export it.$ drupal config:export:content:type &gt; video Export content type in module as an optional configuration (yes/no) [yes]: &gt; no</p></li><li><p>Can we generate some example content? Yes we can.$ drupal create:nodes</p></li><li><p>5. Create Admin form using Console$ drupal generate:form:config Enter the Form Class name [DefaultForm]: &gt; ImportSettingsForm Do you want to generate a form structure? (yes/no) [yes]: &gt; y Type: number Input label: Import Max Description: Maximum amount of nodes to import pre cron run Default value: 10 Type: textfield Input label: Search Terms Description: Feed to import from Default value: macaframa </p></li><li><p>Export the configuration settings.$ drupal config:export:single --directory=modules/custom/fastpaced_videos/config/install Configuration type [Simple configuration]: &gt; system.simple Configuration name [automated_cron.settings]: &gt; fastpaced_videos.importsettings</p></li><li><p>6. Import Nodes using GuzzleAdd fastpaced_videos_cron().</p><p>/** * @file * Contains fastpaced_videos.module. */ use Drupal\Core\Url; use Drupal\Component\Serialization\Json; /** * Implements hook_cron(). */ function fastpaced_videos_cron() {...}</p><p>Some parts of Drupal 8 are still procedural like 7, hook_theme and hook_cron, for example.</p><p> for further changes to fastpaced_videos.moduleRefer to the repo</p><p></p></li><li><p>7. Create a Service using ConsoleWe'll be importing videos using guzzle, so we'll need to create</p><p>a service to save them.$ drupal generate:service Enter the service name [fastpaced_videos.default]: &gt; fastpaced_videos.import Enter the Class name [DefaultService]: &gt; ImportService Do you want to load services from the container (yes/no) [no]: &gt; yes Enter your service [ ]: &gt; entity.query &gt; entity_type.manager</p><p> for further changes to fastpaced_videos/src/ImportServiceInterface.phpRefer to the repo</p><p></p></li><li><p>8. Add your custom module to composerAdd as a repo, </p><p>so we can can download our custom module.our github repo</p><p>"repositories": [... { "type": "git", "url": "" }]</p><p>$ composer require emarchak/fastpaced_videos</p><p></p></li><li><p>Ride eternal, shiny and chrome. / @emarchak @myplanetHQ</p><p> /</p><p></p></li></ul>