Faster & Smarter Development

with Drupal Console


About me



Jesus Manuel Olivas

Drupal 8 Solutions Engineer









I work for FFW

(and you should too)

Topics


  • Drupal Console the what, why and how.
  • Generate code/files required by a Drupal 8 module.
  • Interact and Debug Drupal 8.
  • Learn Drupal 8.
  • Write an integration.
  • Automate command execution.
  • Remote command execution.
  • Contribute to the project and Roadmap.

What is the Drupal Console?



The Drupal Console is a CLI tool to generate boilerplate code, interact and debug Drupal 8.

Who maintain this project?


David Flores ‏| @dmouse

Eduardo García | @enzolutions

Jesús Manuel Olivas | @jmolivas

Omar Aguirre | @omers

Supporting organizations





Why should you care about it?

Drupal is more tehcnically advanced


The HTTP Lifecycle

In every web application, in any language, you always have one goal, read and understand the incoming HTTP request in order to create and return the appropriate HTTP response.

The Request/Response Flow



How Drupal 8 builds your pages

Routing



A route is a map from a URL path to a controller.

Controller



A controller is a PHP method or call-back that takes information from the HTTP request and constructs and returns an HTTP response.

How does Drupal Console help?

  • Generate boilerplate code for Drupal 8.
  • Interact and debug Drupal 8.
  • Learn Drupal 8.

Where do you find the project?



Landing Page

http://drupalconsole.com/


Documentation

http://bit.ly/console-book


Support

http://bit.ly/console-support

Download Drupal Console

Using the installer


# 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

# Check and validate system requirements
drupal check

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

Using Composer



$ composer global require drupal/console:@stable

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

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


Gitbook - Using Composer

Using Drupal Composer



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


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

Using a Virtual Machine / Container


Updating the project




$ drupal self-update

$ php console.phar self-update

$ composer global update drupal/console

Copy configuration files

drupal init

Validate system requirements

drupal check

site:new

site:install

chain

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

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

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

Execute Drupal Console


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

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

Generate the code and files

required by a Drupal 8 module.

Creating a module


  • Create a new directory named 'example' at 'modules/custom' directory.
  • Create an 'example.info.yml' file at 'modules/custom/example' directory.

Custom and contributed modules must be created at modules folder in the root directory.

generate:module

Creating a Custom Page


  • Create a 'HelloController' Class with a 'hello' method at 'src/Controller' Directory.

  • Create a route with path to '/hello/{name}' at 'example.routing.yml' file.

Make sure your HelloController class extends from ControllerBase core class.

generate:controller

Creating a Config Form


  • Create a 'ExampleForm.php' class at 'src/Form' Directory.
  • Create a route with path to '/admin/config/example/example' at 'example.routing.yml'.
  • Add example.links.menu.yml file and set system.admin_config_system as parent.

Make sure you use _form instead of _controller on route defaults.

generate:form:config


example.routing.yml

src/Form/ExampleForm.php

src/Form/ExampleForm.php

src/Form/ExampleForm.php

Creating a Block (Plugin)


  • Create a 'ExampleBlock' class at 'src/Plugin/Block'.
  • Extend from BlockBase core class.
  • Add @Block annotation.
  • Add blockForm, blockSubmit and build methods.

Adding the @Block annotation, make this block discoverable by the system.

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

Interact and debug Drupal 8.

drupal container:debug

container:debug

drupal container:debug | peco

drupal router:debug

drupal router:debug | peco | awk '{print $1}' | xargs drupal router:debug

drupal router:debug user.login

drupal site:mode dev [1/2]

Performance

/admin/config/development/performance

Views settings

/admin/structure/views/view/content

Logging and errors

/admin/config/development/logging

drupal database:log:debug --reverse
--limit=20

drupal database:log:debug 828

drupal site:mode dev [2/2]

Twig debug

site



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

config



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

Learn Drupal 8.

Use --learning option



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

Write an integration

generate:command



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

webprofiler






https://www.drupal.org/project/webprofiler

webprofiler:benchmark


webprofiler


  webprofiler:benchmark             
  webprofiler:export                
  webprofiler:list                  

Remote command execution

Global configuration

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

Site configuration

~/.console/sites/sample.yml


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

site:debug

site:debug sample.dev

--target || @



$ drupal --target=sample.dev cr all

$ drupal @sample.dev cr all

Remote site execution



Tips

#Protip 1

Use multilanguage feature


# ~/.console/config.yml

application:
  environment: 'prod'
  language: en
  editor: vim
  temp: /tmp


drupal config:set language es

#Protip 2

Use default values


# ~/.console/commands.yml
application:

...

  default:
    commands:
      generate:
        controller:
          options:
            module: my_current_project

#Protip 3

Disable contributed commands


# ~/.console/commands.yml
application:

...

  disable:
    modules:
      - broken_module_name_one
      - broken_module_name_two

#Protip 4

Use --generate-inline


$ drupal generate:entity:config --generate-inline

#Protip 5

Use --generate-chain


$ drupal generate:module --generate-chain

How to contribute?

Getting the project


Fork your own copy of the Console repository

http://bit.ly/console-fork


Clone your forked repository.


$ git clone git@github.com:[github-user]/DrupalConsole.git


Download dependencies using componser.


$ cd /path/to/DrupalConsole
$ composer install

Before commiting your code


Project code is PSR-2 Coding Style.

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


Generated code is Drupal Coding Style.

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

Code analysis



http://bit.ly/console-insight




http://bit.ly/console-travis

PHPQA all-in-one Analyzer CLI tool


  • PHP Parallel Lint
  • PHP_CodeSniffer
  • PHPLOC
  • PHP Mess Detector
  • PHPUnit

https://github.com/jmolivas/phpqa

Running PHPQA manually


$ cd /path/to/DrupalConsole
$ phpqa analyze --files=src/


Running PHPQA automatically


$ vim .git/hooks/pre-commit
# Paste this:
phpqa analyze --git

Contributors


https://drupalconsole.com/contributors

Spread the word and love.




@drupalconsole | #drupalconsole

Roadmap

Increase code coverage.

Improve documentation and translations.

Improve verbose code-output.

Milestones


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

Current and upcomming implementations


Webprofiler (devel submodule)

Meta tag

Drupal Commerce

Scheduled Updates

Rules

Casper (theme)

[Your module here]

What if ... I am not a CLI guru

GUI for the CLI.



WebApp => ReactJS

http://drupalgenerator.com/

How about a Native app?.



NativeApp => Electron

Questions & Feedback


Feel free to stalk me or ask any question at:


@jmolivas | @drupalconsole