On Github jmolivas / speeding-up-drupal-8-development-using-drupal-console
DrupalCamp Costa Rica 2015
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 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:
That take advantage of Symfony Console Component and other third party libraries.
David Flores | @dmouse
Eduardo García | @enzolutions
Jesús Manuel Olivas | @jmolivas
Omar Aguirre | @omers
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.
I want to thank the agencies sponsoring this project.
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.
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.
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.
Well, I think that was sooooo much talking.
Why don't we try something more fun and show you how Drupal Console looks like.
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
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.
Depending on the download method:
$ drupal self-update $ console self-update $ php console.phar self-update
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.
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.
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.
$ drupal generate:plugin:block --module="drupalcon" --class-name="ExampleBlock" --label="example_block" --plugin-id="example_block" --no-interaction
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.
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.
$ drupal generate:entity:content --module="drupalcon" --entity-class="Foo" --entity-name="foo" --no-interaction
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.
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.
$ drupal generate:controller --module="drupalcon" --class-name="HelloController" --method-name="hello" --route="/hello/{name}" --learning --no-interaction
However, this approach coud not be enough.
For that reason we provide you with an option to provide extra information to the generated code.
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.
If you are a module maintainer. You can write an integration to take advantage of drupal console features.
$ drupal generate:command --module="drupalcon" --class-name="HelloCommand" --command="example:hello" --no-interaction
The easy way to generate an integration is to execute the generate:command command.
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.
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.
As you can see this integration enables users, to run benchmarks agains a Drupal installation.
$ drupal chain --file=~/path/to/start-project.yml
generate generate:authentication:provider generate:entity:content generate:permissions generate:plugin:imageeffect generate:plugin:rest:resource generate:plugin:rulesaction generate:service
generate:theme
migrate migrate:debug migrate:execute migrate:load module module:uninstall password password:hash password:reset
rest rest:debug rest:disable rest:enable test test:debug
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.
Fork your own copy of the Console repository
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
... Getting the project is as easy as follow this 3 steps.
Fork the project
Clone your fork
Download dependencies
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.
We have the Platinum medal:
No single violation in the whole codebase of this project .
Our current build is passing.
This is the hall of fame of Drupal Console, with out this people we would not be speaking at this conference.
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.
A VM for local Drupal development, built with Vagrant + Ansible
Simple Drupal 8 Development Environment
What features are planned for development?
At this point, probably some of you are worried or wondering about overlaping with drush.
Before we wrap up, I like to talk about a planned feature.
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.
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.