Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8

88
Drupal Console Deep Dive @drupalconsole | #drupalconsole

Transcript of Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8

DrupalConsoleDeepDive

@drupalconsole|#drupalconsole

JesusManuelOlivas

Drupal8SolutionsEngineer|

IworkforFFW(andyoushouldtoo)

Aboutme

@jmolivas @drupalconsole@drupodcast

Topics

DrupalConsolethewhat,whyandhow.

Generatecode/filesrequiredbyaDrupal8module.

InteractandDebugDrupal8.

LearnDrupal8.

Writeanintegration.

Automatecommandexecution.

Remotecommandexecution.

ContributetotheprojectandRoadmap.

WhatistheDrupalConsole?

ThenewCLIforDrupal.

TheDrupalConsoleisatooltogenerateboilerplatecode,interactanddebugDrupal8.

DavidFlores |@dmouse

EduardoGarcía|@enzolutions

JesúsManuelOlivas|@jmolivas

OmarAguirre|@omers

Whomaintainthisproject?

Whyshouldyoucareaboutit?

Drupalismoretehcnicallyadvanced

HowdoesDrupalConsolehelp?

GenerateboilerplatecodeforDrupal8.

InteractanddebugDrupal8.

LearnDrupal8.

Wheredoyou ndtheproject?

LandingPage

Documentation

Support

http://drupalconsole.com/

http://bit.ly/console-book

http://bit.ly/console-support

DownloadDrupalConsole

Usingtheinstaller

# Run this in your terminal to get the latest project version:curl https://drupalconsole.com/installer -L -o drupal.phar

# Accessing from anywhere on your system:mv drupal.phar /usr/local/bin/drupal

# Apply executable permissions on the downloaded file:chmod +x /usr/local/bin/drupal

# Copy configuration files to user home directory:drupal init --override

# Check and validate system requirementsdrupal check

UsingComposer

$ composer global require drupal/console:@stable

# download path:# ~/.composer/vendor/drupal/console

# run it using:$ ~/.composer/vendor/bin/console

Gitbook-UsingComposer

UsingDrupalComposer

$ composer create-project drupal-composer/drupal-project:8.x-dev drupal8.dev --stability dev --no-interaction

https://github.com/drupal-composer/drupal-project

UsingaVirtualMachine/Container

DrupalVM

Drupal8SprintBox

DrupaldevelopmentwithDocker

Drude(DrupalDockerEnvironment)

http://www.drupalvm.com/

https://github.com/thom8/drupal8-vagrant

https://github.com/wadmiraal/docker-drupal

https://github.com/blinkreaction/drude

Updatingtheproject

$ drupal self-update

$ php console.phar self-update

$ composer global update drupal/console

Copycon guration lesdrupalinit

Validatesystemrequirementsdrupalcheck

site:new

site:install

chain

chainchain--file=~/.console/chain/quick-start.yml

~/.console/chain/quick-start.yml

drupalchain--file=~/.console/chain/quick-start-mysql.yml

ExecuteDrupalConsole

# change directory to site path$ cd /var/www/drupal8.dev$ drupal

# use --root option$ drupal --root=/var/www/drupal8.dev

Generatethecodeand lesrequiredbyaDrupal8module.

Creatingamodule

Createanewdirectorynamed'example'at'modules/custom'directory.

Createan'example.info.yml'fileat'modules/custom/example'directory.

Customandcontributedmodulesmustbecreatedatmodulesfolderintherootdirectory.

generate:module

CreatingaCustomPage

Createa'HelloController'Classwitha'hello'methodat'src/Controller'Directory.

Createaroutewithpathto'/hello/{name}'at'example.routing.yml'file.

MakesureyourHelloControllerclassextendsfromControllerBasecoreclass.

generate:controller

CreatingaCon gForm

Createa'ExampleForm.php'classat'src/Form'Directory.

Createaroutewithpathto'/admin/config/example/example'at'example.routing.yml'.

Addexample.links.menu.ymlfileandsetsystem.admin_config_systemasparent.

Makesureyouuse_forminsteadof_controlleronroutedefaults.

generate:form:con g

example.routing.yml

src/Form/ExampleForm.php

src/Form/ExampleForm.php

src/Form/ExampleForm.php

CreatingaBlock(Plugin)

Createa'ExampleBlock'classat'src/Plugin/Block'.

ExtendfromBlockBasecoreclass.

Add@Blockannotation.

AddblockForm,blockSubmitandbuildmethods.

Addingthe@Blockannotation,makethisblockdiscoverablebythesystem.

generate:plugin:block

$ drupal generate:plugin:block --module="example" --class="ExampleBlock" --label="example_block" --plugin-id="example_block" --no-interaction

generate:entity:content

$ drupal generate:entity:content --module="example" --entity-class="Foo" --entity-name="foo" --no-interaction

InteractanddebugDrupal8.

drupalcontainer:debug

container:debug

drupalcontainer:debug|peco

drupalrouter:debugdrupalrouter:debug|peco|awk'{print$1}'|xargsdrupalrouter:debug

drupalrouter:debuguser.login

drupalsite:modedev[1/2]

Performance/admin/config/development/performance

Viewssettings/admin/structure/views/view/content

Logginganderrors/admin/config/development/logging

drupalsite:modedev[2/2]

Twigdebug

drupaldatabase:log:debug--reverse--limit=20

drupaldatabase:log:debug828

site

site site:maintenance [ON/OFF] site:status

con g

config config:debug config:edit config:export config:export:content:type config:export:single config:export:view config:import config:import:single config:override

user

user user:login:clear:attempts user:login:url user:password:hash user:password:reset

LearnDrupal8.

Use--learningoption

$ drupal generate:controller --module="example" --class="ExampleController" --routes="title:hello method:hello path:/hello/{name}" --test --no-interaction --learning

Writeanintegration

generate:command

$ drupal generate:command --module="example" --class-name="HelloCommand" --command="example:hello" --no-interaction

Remotecommandexecution

Globalcon guration~/.console/config.yml

application:

...

remote: user: root port: 22 console: /usr/local/bin/drupal keys: public: ~/.ssh/id_rsa.pub private: ~/.ssh/id_rsa passphrase: ~/.ssh/passphrase.txt

Sitecon guration~/.console/sites/sample.yml

local: root: /var/www/drupal8.dev host: localdev: root: /var/www/html/drupal host: 140.211.10.62 user: drupalprod: root: /var/www/html/docroot host: live.drupal.org user: drupal console: /var/www/html/docroot/console.phar

site:debug

site:debugsample.dev

--target||@

$ drupal --target=sample.dev cr all

$ drupal @sample.dev cr all

Remotesiteexecution

Howtocontribute?

GettingtheprojectForkyourowncopyoftheConsolerepository

Cloneyourforkedrepository.

$ git clone [email protected]:[github-user]/DrupalConsole.git

Downloaddependenciesusingcomponser.

$ cd /path/to/DrupalConsole$ composer install

http://bit.ly/console-fork

Beforecommitingyourcode

ProjectcodeisPSR-2CodingStyle.

GeneratedcodeisDrupalCodingStyle.

http://www.php-fig.org/psr/psr-2/

https://www.drupal.org/coding-standards

Contributors

https://drupalconsole.com/contributors

Spreadthewordandlove.

@drupalconsole|#drupalconsole

Roadmap

Increasecodecoverage.

Improvedocumentationandtranslations.

Improveverbosecode-output.(--learning)

Improveautomatecapabilities.(chain)

Milestones

https://github.com/hechoendrupal/DrupalConsole/milestones

Currentandupcommingimplementations

Webpro ler(develsubmodule)

Metatag

DrupalCommerce

ScheduledUpdates

Rules

Casper(theme)

Liberty(theme)

Whatif...IamnotaCLIguru

GUIfortheCLI.

Desktop/Nativeapplicationusing

Electron

ReactJS

ES6

Questions&Feedback

Feelfreetostalkmeoraskanyquestionat:

@jmolivas|@drupalconsole