Faster & Smarter Development – with Drupal Console



Faster & Smarter Development – with Drupal Console

5 1


speeding-up-drupal-8-development-using-drupal-console


On Github jmolivas / speeding-up-drupal-8-development-using-drupal-console

Speeding up Drupal 8 development using Drupal Console

DrupalCamp Costa Rica 2015

@enzo

Hola que tal a todos, gracias por estar asistir, estamos aqui para platicar sobre Drupal Console, una herramienta para Drupal ocho que se ejecuta en la terminal ....

Este proyecto surgio hace 2 DrupalCamps ...

The begining

What is the Drupal Console?

It is a suite of tools that you run on a command line interface (CLI) to generate boilerplate code and interact with a Drupal 8 installation.

jmolivas

The Drupal Console is a suite of tools that you run on the (CLI) to generate boilerplate code and interact with a Drupal 8 installation.

I want to clarify one important point:

  • Drupal Console is not a Drupal Module.
  • Drupal Console is a Symfony Application.

That take advantage of Symfony Console Component and other third party libraries.

Who maintain this project?

David Flores ‏| @dmouse

Eduardo García | @enzolutions

Jesús Manuel Olivas | @jmolivas

Omar Aguirre | @omers

enzo

This project was started back in 2013 by David Flores Jesus Manuel Olivas both Mexican developers.

But as the project start getting some traction, two other developers join to help co-maintaing it.

Omar Aguirre a developer from Mexico.

And myself Eduardo García a Colombian developer living in Costa Rica.

Dia 13

#noEraPenalCR ...

#yTampocoPanama ...

Supporting organizations

enzo

I want to thank the agencies sponsoring this project.

  • FFW (formerly Blink Reaction and Propeople) the biggest drupal agency on the world. Is sponsoring me to work full time in this project.
  • Indava a Web developer agency in Mexico is sponsoring David's contributions.
  • AnexusIT the oldest and biggest DrupalShop in Costa Rica is sponsoring enzo's contributions.
  • The only one living in the wild is Omar Aguirre, please feel free to invite him a beer or two.

Why should you care about it?

Drupal is more tehcnically advanced

@omers

Drupal is more complex than other Content Management Systems.

How many of you, have begun to explore Drupal 8 already?, If you are not yet, I can tell you there is a whole new set of concepts to learn.

Managing the increasing complexity of Drupal 8 can be a daunting task for anyone, are you prepared for it? Drupal Console is a suite of tools to help manage that complexity. Follow along as we explore this tool.

How does Drupal Console help?

Drupal Console help you developing faster and smarter with Drupal 8.

@jmolivas

Generating the code and files required by a Drupal 8 module.

Interacting with your Drupal installation.

Learning Drupal 8.

jmolivas

Drupal Console provides a number of commands for creating module scaffolding and boilerplate code. For any command, you will be asked a series of questions about what you want to generate.

Drupal Console allows you to interact with your Drupal installation from rebulding cache to configuration management.

You can even learn Drupal 8, inspecting the generated code while using --learning option.

Where do I find the project?

Landing Page

http://drupalconsole.com/

Documentation

http://bit.ly/console-book

Support

http://bit.ly/console-support

omers

Just by visiting the project landing page.

drupalconsole.com

In this landing page you will find information and links about documentation and how to get support.

Download Drupal Console

jmolivas

Well, I think that was sooooo much talking.

Why don't we try something more fun and show you how Drupal Console looks like.

Using the Installer

Install the Console locally by running the installer in your project directory:

$ curl -LSs http://drupalconsole.com/installer | php

Access console from anywhere on your system

$ mv console.phar /usr/local/bin/drupal

You can now execute console using:

$ drupal

jmolivas

There are different ways to get the project on your local machine.

Our recomendation for getting the project on your local machine is by using the installer.

jmolivas

As you can see on the video the installer download the necesary files to run drupal console on you computer.

Updating the project

Depending on the download method:

$ drupal self-update

$ console self-update

$ php console.phar self-update

jmolivas

Drupal 8 is under heavy development, to keep in sync with the latest changes. The easiest and recommended way of updating Console is using the self-update command.

What can you do with

Drupal Console?

omers

Lets see some commands in action.

Generate the code and files

required by a Drupal 8 module.

omers

generate:module

omers

As you can see, the video is using the interactive mode where the user can provide the basic information (like module, name, ...) to generate a custom Drupal 8 moddule.

As result we get a brand new module and fully funcional module. Ready to be used on you Drupal 8 installation.

enzo

generate:form:config

enzo

enzo

Lets tal about form generation.

What do you need to generate a Form in Drupal 8. You need a route, a form and field definition and integration with the configuration managemente in order to save user input.

At the end we get a funcional form. User can enter data and that will be save on the system.

generate:plugin:block

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

enzo

So far we have seen the interactive mode, which it is a little bit more flashy since you can see the questions and the entered answer.

But, starting from now we will show how to execute commands passing inline arguments, which is way more faster.

enzo

Blocks in Drupal 8 are plugins, creating a plugin can be a little tricky, because you need to add annotations in order to this new block can be discoverable by the system.

But do not worry, beacuse console take care of adding them.

generate:entity:content

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

jmolivas

jmolivas

Adding an entity on Drupal 8 is a complex task. You need to create/update about 14 files.

Those files are classes, forms, routes and menu links. The provided entity is fieldable from de UI.

Entities are plugins and require to add annotations same as in the block generation that code is added by the command.

Interact with your Drupal

installation.

omers

We started the project as a scaffolding code generator.

But eventually we have needed to test the generated code.

For that reason we added commands to interact with the Drupal Installation.

omers

  • As you can see we have commands to interact with the configurations system you can list, edit, import and export configurations.
  • You can also debug the routing system, listing routes and displaying a specific route information.
  • Also you can download, list, install, unistall modules and check the status of them.

Learn Drupal 8.

Using --learning option

$ drupal generate:controller
  --module="drupalcon"
  --class-name="HelloController"
  --method-name="hello"
  --route="/hello/{name}"
  --learning
  --no-interaction

jmolivas

  • I can imagine some of you, are thinking in use the generated code to learn Drupal 8 by applying Reverse Engineering.

However, this approach coud not be enough.

For that reason we provide you with an option to provide extra information to the generated code.

jmolivas

Using the --learnig the generator will not only generate code, will also add comments describing the generated code.

Think about the commented code at examples module.

Write an integration

jmolivas

If you are a module maintainer. You can write an integration to take advantage of drupal console features.

generate:command

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

jmolivas

The easy way to generate an integration is to execute the generate:command command.

enzo

This command will generate all the boiler-plate code to write a new command within your drupal 8 module.

From there you can implement your bussines logic.

webprofiler

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

jmolivas

Let me tell you about the awesome webprofiler project. Which is an implementation of Symfony WebProfiler.

This module was the first module to take advantage of Drupal Console features.

jmolivas

As you can see this integration enables users, to run benchmarks agains a Drupal installation.

Automate command execution

$ drupal chain
  --file=~/path/to/start-project.yml

enzo

  • We have mentioned how to run individual commands.
  • But if you are looking to automate command execution you can use the chain command.

enzo

  • The chain command reads a configuration file and execute several commands based on the sequence defined in the configuration file.
  • We decide to use a standard YAML file extension and not go with something like chain extension because we did not want to add a new Drupalism to the project.

Other commands 1/3

generate
 generate:authentication:provider
 generate:entity:content
 generate:permissions
 generate:plugin:imageeffect
 generate:plugin:rest:resource
 generate:plugin:rulesaction
 generate:service

omers

For the front-end devs ...

 generate:theme

Other commands 2/3

migrate
 migrate:debug
 migrate:execute
 migrate:load
module
 module:uninstall
password
 password:hash
 password:reset

omers

Other commands 3/3

rest
 rest:debug
 rest:disable
 rest:enable
test
 test:debug

omers

How to contribute?

jmolivas

Now that we mentioned about integration, I like to talk about contribution.

Anyone can contribute, you can add new features, write an integration with your custom module, improve transaltions and documentation.

But first you need to get the code right.

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:[your-git-user-here]/DrupalConsole.git

Download dependencies using componser.

$ cd /path/to/DrupalAppConsole
$ composer update --no-dev

jmolivas

... Getting the project is as easy as follow this 3 steps.

Fork the project

Clone your fork

Download dependencies

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

jmolivas

Before commiting your code you need to know

Since Drupal Console is not a Drupal module is a Symfony application, project code is PSR-2 Coding Style.

But don't worry, generated code is Drupal Coding Style.

Code analysis

http://bit.ly/console-insight

http://bit.ly/console-travis

jmolivas

We have the Platinum medal:

No single violation in the whole codebase of this project .

Our current build is passing.

PHPQA all-in-one Analyzer CLI tool

  • PHP Parallel Lint
  • PHP_CodeSniffer
  • PHPLOC
  • PHP Mess Detector
  • PHPUnit
https://github.com/jmolivas/phpqa

Contributors

jmolivas
dmouse
enzolutions
omero
danielnv18
vacho
esod
cordoval
Sutharsan
chipkaye
hugronaphor
kgaut
webflo
czettnersandor
fluxsauce
greg-1-anderson
lucasmingarro
Crell
martinfrances107
bojanz
danielrose28
MiguelC301
azarzag
Jaesin
rpayanm
iadyax
alexweber
mimioc
revagomes
Chi-teck
egulias
heilop
LowellMontgomery
mmenavas
sethfischer
emacoti
jeqq
benjy
carlosroh
edutrul
albertvolkman
jjcarrion
dasjo
joshuataylor
kendallsv
kostajh
lussoluca
stevector
ysramirez
brantwynn
langelhc

enzo

This is the hall of fame of Drupal Console, with out this people we would not be speaking at this conference.

Where are they from

enzo

Are you wondering where are they from ?

As you can see, this is mostly a LatinAmerican project and it's a proof our region can create techonlogy to share with the rest of the world.

And with your help we can create a much better project.

Other resources

Spread the word and love.

/~drupalconsole

@drupalconsole | #drupalconsole

jmolivas

We need all of the help we can get, please use the project and love it or hate it, let us know.
  • Providing feedback.
  • Asking for new features.
  • Creating issues and sending pull requests.
  • Talking and Tweeting about this project and Proudly showing your Drupal Console sticker. Ping us for stickers at the end.

Roadmap

Upcomming features

Increase code coverage.

Improve documentation and translations.

Improve verbose code-output.

Remote command execution.

Dummy content generation.

Content staging export/import.

jmolivas

What features are planned for development?

  • Improve verbose code-output for learning. (Please let us know in which generators do you want to see this feature, we want to hear form you)
  • Generate dummy content. Probably using Faker library or Default Content project.
  • Content Staging export/import content.

At this point, probably some of you are worried or wondering about overlaping with drush.

Upcomming implementations

Rules

Meta tag

[Your module here]

Milestones

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

Call Drupal Console commands from Drush

https://github.com/drush-ops/drush/pull/1337

One more thing...

jmolivas

Before we wrap up, I like to talk about a planned feature.

GUI for the CLI.

jmolivas

As mentioned before the goal of this project is provide a tool easy to use for everyone.

We are plannig a GUI for the CLI.

http://drupalgenerator.com/

jmolivas

We really want to make the tool even more accessible to all site administrators of Drupal 8.

Adding a GUI for Drupal Console as an alternative to the CLI.

This could be especially useful for site builders wanting to take advante of this tool without needing to use the command line.

It could be used for code generation in the form of a downloadable compressed file.

Questions & Feedback

Feel free to stalk us during the event or ask any question at:

@jmolivas | @enzolutions | @omers | @drupalconsole

http://bit.ly/no-era-penal-cr

Speeding up Drupal 8 development using Drupal Console DrupalCamp Costa Rica 2015 @enzo Hola que tal a todos, gracias por estar asistir, estamos aqui para platicar sobre Drupal Console, una herramienta para Drupal ocho que se ejecuta en la terminal .... Este proyecto surgio hace 2 DrupalCamps ...