2. Recap
1. Introduction to drush and drupal console.
2. Comparison between drush and drupal console.
3. Drupal console installation.
4. How to use drush.
5. Scaffolding.
6. Tree structure using command.
7. Create virtual server using drush.
3. Precap
1. What is Drupal Console?
2. Why Drupal Console?
3. How to use drupal console.
4. Generate a module.
5. Generate an entity.
6. Generate a profile.
7. Generate a theme.
8. Generate a custom command.
4. What is drupal console?
The Drupal Console is, at this time, a suite of tools that you run on a command
line interface(CLI) to generate boilerplate code and interact with a Drupal 8
installation.
Similar tools include:
1. Module Builder: Generate Drupal 6,7 or 8 module scaffolding.
2. Drupal Module Upgrader: Converts modules from Drupal 7 to Drupal 8,
generated static help files with links to relevant change records.
3. Drupal 8 Tools: Drupal code generator written in bash.
4. Drush: Interact with Drupal installation via CLI, creates aliases, create custom
5. Why Drupal Console?
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. In the case of module scaffolding, files are created and
inside these files, classes—complete with namespacing and use statements—are
created for you with the naming convention you specified in the command's
prompts.
The Drupal Console isn't a Drupal module, but was built with the Symfony Console
Component and other libraries, such as Twig, to generate PHP, YAML, and other
file types used in Drupal 8 module development. It is a tool designed for anyone
using or planning to use Drupal 8. At the moment, it is used via a CLI, but there
are plans to make it accessible through the Drupal administrative interface.
6. How does Drupal Console differ from Drupal Module
Upgrader?
Drupal Module Upgrader takes a Drupal 7 module and attempts to port it to Drupal
8. While it generates files like Drupal Console does, Drupal Console generates
module scaffolding and code based on a series of interactive prompts, instead of
analyzing an existing module and converting it to work in Drupal 8.
7. How does Drupal Console compare to Drush?
There are many similarities between these two tools, but the main difference is
how it was built, using an object-oriented architecture and Symfony components.
8. Who is the intended audience for the Drupal
Console?
Any developer who will be responsible for writing custom code in Drupal 8. Any
organization that will benefit from its vast potential.
As such, the following groups in particular could find this tool advantageous to add
to their learning Drupal 8 toolkit:
1. Enterprises and other organizations to reduce development time and reduce
custom development risk factors.
2. Drupal 8 module maintainers and developers to speed up development and
testing.
3. Drupal trainers and consultants providing Drupal 8 developer training.
9. What features are planned for development?
1. Verbose code output for learning and leveraging docblocks
2. Complete config:import, site:status, and few a few other commands.
3. Import/export content between Drupal installations
4. Site Aliases
5. Generate dummy content, probably using PHP Faker library or Default
Content project.
6. Add a GUI for Drupal Console as an alternative to the CLI. This could be
especially useful for site builders wanting to generate dummy content or issue
site commands without needing to use the command line. It could also be
10. How to use drupal console?
1. You can install it using curl
curl https://drupalconsole.com/installer -L -o drupal.phar
2. Using PHP in CLI
php -r "readfile('https://drupalconsole.com/installer');" > drupal.phar
3. Using Composer
composer global require drupal/console:@stable
11. Generate a module
For generating a custom module we can use below command for a fresh drupal 8
custom module generation. Please note you must be in a drupal 8 project
directory.
drupal generate:module
It will lead you to interactive CLI and will need some inputs from your side and
generates the custom module.
12. Generate an entity
For generating a custom entity we can use below command for a fresh drupal 8
entity generation inside a custom module. Please note you must be in a drupal 8
project directory.
drupal generate:entity:config
It will lead you to interactive CLI and will need some inputs from your side and
generates the custom entity along with its table.
It also provides admin interface for managing the created entity(Asked on the
CLI).
13. Generate a profile
For generating a custom profile we can use below command for a drupal 8 profile.
Please note you must be in a drupal 8 project directory.
drupal generate:profile
It will lead you to interactive CLI and will need some inputs from your side and
generates the profile and can be developed as distribution.
14. Generate a Custom Command
We can generate a custom drupal console command too. For generating a custom
command we can use below command. Please note you must be in a drupal 8
project directory and it will ask you for a module where the new command can be
inserted..
drupal generate:command
It will lead you to interactive CLI and will need some inputs from your side and
generates the command along with some example to show interactive feature.
15. Introduction to command class
As we are using symphony for drupal, it provides interaction with CLI using its
console package command class which present at below path.
vendor/symfony/console/Command/Command.php
Drupal also inherited this class and generates its own class. All the drupal console
commands generated using the above classes and can be available for CLI
interaction.
16. Command class structure and understanding
If we want to generate a custom command, we should use below namespaces.
use SymfonyComponentConsoleInputInputArgument;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleInputInputOption;
use SymfonyComponentConsoleOutputOutputInterface;
use DrupalConsoleCommandCommand;
use DrupalConsoleStyleDrupalStyle;
Also our custom class package must be extend Command base class. Which
contains and handlers all the commands executed for drupal console.
17. Continue….
In our command class we should implement 2 functions, which will handle the
command Execution.
protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
Configure function defines the command, its description, arguments, and options.
We just need to override it by extending Command class.
Execute function define how the command will get executed, and what will be
input and output.
18. More drupal console commands
You can find more drupal console commands at drupalconsole.com cheatbook,
using below URL.
http://drupalconsole.com/cheatsheet/
Also, if we need help regarding any console command we can use below
command to get help and syntax.
Drupal help drupalconsole:command