24
Fast Paced Drupal 8 Speed up with composer, console and services / @emarchak @myplanetHQ / emarchak.github.io/fastpaced_drupal8 github.com/emarchak/fastpaced_videos

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

  • Upload
    acquia

  • View
    915

  • Download
    2

Embed Size (px)

Citation preview

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

Fast PacedDrupal 8

Speed up with composer, console and services / @emarchak @myplanetHQ

/ emarchak.github.io/fastpaced_drupal8 github.com/emarchak/fastpaced_videos

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

Why Change for D8?1. Speed up your development process2. Play well with others

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

DependenciesDependency 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)

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

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

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

Witness Me!

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

1. Build using ComposerDownload Drupal into the docroot.

to Drush Make for building sites.Composer is a really exciting alternative

$ composer create-project drupal/drupal docroot 8.0.5 $ cd docroot

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

Managing patches using composerFor Drupal 8.0.5 only, we'll need to , but any module can be patched.patch core

$ composer require cweagans/composer-patches --no-update

"extra": {... "patches": { "drupal/drupal": { "Combination of --prefer-dist and .gitattributes confuses our vendor test cleanup" } }

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

Add to installer paths to let us download modules to./docroot/modules/contrib

"extra": {... "installer-paths": { "modules/contrib/{$name}": [ "type:drupal-module" ] } },

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

Add as a repo,so we can download Drupal modules.

Drupal Composer

"repositories": [ { "type": "composer", "url": "https://packagist.drupal-composer.org" } ]

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

Install some Drupal modules! improves the core Drupal toolbar,

and is used in our demo.Admin Toolbar

Video Embed Field

$ composer require drupal/admin_toolbar:8.1.14 --no-update $ composer require drupal/video_embed_field:8.1.0-rc5 --no-update $ composer update

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

2. Install using Console$ drupal site:install $ drupal module:install admin_toolbar $ drupal module:install video_embed_field

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

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$' ];

$ drupal config:export

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

3. Create a Module using ConsoleLet's create a fast-paced module...

$ drupal generate:module Enter the new module name: > Fastpaced videos

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

... and a speedy content type!$ drupal generate:entity:bundle Enter the module name [admin_toolbar]: > fastpaced_videos Enter the machine name of your new content type [default]: > video $ drupal module:install fastpaced_videos

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

4. Export Content Types using ConsoleLog into the site and configure the content type as needed,

before you export it.$ drupal config:export:content:type > video Export content type in module as an optional configuration (yes/no) [yes]: > no

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

Can we generate some example content? Yes we can.$ drupal create:nodes

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

5. Create Admin form using Console$ drupal generate:form:config Enter the Form Class name [DefaultForm]: > ImportSettingsForm Do you want to generate a form structure? (yes/no) [yes]: > 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

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

Export the configuration settings.$ drupal config:export:single --directory=modules/custom/fastpaced_videos/config/install Configuration type [Simple configuration]: > system.simple Configuration name [automated_cron.settings]: > fastpaced_videos.importsettings

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

6. Import Nodes using GuzzleAdd fastpaced_videos_cron().

/** * @file * Contains fastpaced_videos.module. */ use Drupal\Core\Url; use Drupal\Component\Serialization\Json; /** * Implements hook_cron(). */ function fastpaced_videos_cron() {...}

Some parts of Drupal 8 are still procedural like 7, hook_theme and hook_cron, for example.

for further changes to fastpaced_videos.moduleRefer to the repo

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

7. Create a Service using ConsoleWe'll be importing videos using guzzle, so we'll need to create

a service to save them.$ drupal generate:service Enter the service name [fastpaced_videos.default]: > fastpaced_videos.import Enter the Class name [DefaultService]: > ImportService Do you want to load services from the container (yes/no) [no]: > yes Enter your service [ ]: > entity.query > entity_type.manager

for further changes to fastpaced_videos/src/ImportServiceInterface.phpRefer to the repo

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

8. Add your custom module to composerAdd 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" }]

$ composer require emarchak/fastpaced_videos

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

Ride eternal, shiny and chrome. / @emarchak @myplanetHQ

/ emarchak.github.io/fastpaced_drupal8 github.com/emarchak/fastpaced_videos