fast paced drupal 8: accelerating development with composer, drupal console and services

Post on 21-Feb-2017

915 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Fast PacedDrupal 8

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

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

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

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)

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

Witness Me!

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

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" } }

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

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

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

Drupal Composer

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

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

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

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

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

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

... 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

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

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

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

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

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

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

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

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

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

top related