SlideShare a Scribd company logo
1 of 20
Drupal 8 CLI
Command line interface
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.
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.
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
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.
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.
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.
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.
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
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
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.
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).
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.
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.
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.
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.
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.
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
Any Queries?
Thank you

More Related Content

Similar to Drupal 8 cli

Drupal 8 improvements for developer productivity php symfony and more
Drupal 8 improvements for developer productivity  php symfony and moreDrupal 8 improvements for developer productivity  php symfony and more
Drupal 8 improvements for developer productivity php symfony and moreAcquia
 
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...Acquia
 
Top 15 most popular drupal 8 modules
Top 15 most popular drupal 8 modulesTop 15 most popular drupal 8 modules
Top 15 most popular drupal 8 modulesInnoraft
 
[Srijan Wednesday Webinars] Faster and Smarter Development with Drupal Console
[Srijan Wednesday Webinars] Faster and Smarter Development with Drupal Console[Srijan Wednesday Webinars] Faster and Smarter Development with Drupal Console
[Srijan Wednesday Webinars] Faster and Smarter Development with Drupal ConsoleSrijan Technologies
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushPantheon
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesGerald Villorente
 
5 Important Tools for Drupal Development
5 Important Tools for Drupal Development5 Important Tools for Drupal Development
5 Important Tools for Drupal Developmentjcarrig
 
Faster and Smarter Development with Drupal Console
Faster and Smarter Development with Drupal ConsoleFaster and Smarter Development with Drupal Console
Faster and Smarter Development with Drupal ConsoleFFW
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composernuppla
 
Drupal 8 - Improving your development workflow
Drupal 8 - Improving your development workflowDrupal 8 - Improving your development workflow
Drupal 8 - Improving your development workflowvaluebound
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To DrupalLauren Roth
 
Rapid site production with Drupal
Rapid site production with DrupalRapid site production with Drupal
Rapid site production with DrupalRob Sawyer
 
Face your fears: Drush and Aegir
Face your fears: Drush and AegirFace your fears: Drush and Aegir
Face your fears: Drush and AegirIztok Smolic
 
LuisRodriguezLocalDevEnvironmentsDrupalOpenDays
LuisRodriguezLocalDevEnvironmentsDrupalOpenDaysLuisRodriguezLocalDevEnvironmentsDrupalOpenDays
LuisRodriguezLocalDevEnvironmentsDrupalOpenDaysLuis Rodríguez Castromil
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architectureHai Vo Hoang
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module developmentRachit Gupta
 
Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)
Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)
Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)sparkfabrik
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 

Similar to Drupal 8 cli (20)

Drupal 8 improvements for developer productivity php symfony and more
Drupal 8 improvements for developer productivity  php symfony and moreDrupal 8 improvements for developer productivity  php symfony and more
Drupal 8 improvements for developer productivity php symfony and more
 
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
 
Top 15 most popular drupal 8 modules
Top 15 most popular drupal 8 modulesTop 15 most popular drupal 8 modules
Top 15 most popular drupal 8 modules
 
[Srijan Wednesday Webinars] Faster and Smarter Development with Drupal Console
[Srijan Wednesday Webinars] Faster and Smarter Development with Drupal Console[Srijan Wednesday Webinars] Faster and Smarter Development with Drupal Console
[Srijan Wednesday Webinars] Faster and Smarter Development with Drupal Console
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and Drush
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, Terminologies
 
5 Important Tools for Drupal Development
5 Important Tools for Drupal Development5 Important Tools for Drupal Development
5 Important Tools for Drupal Development
 
Faster and Smarter Development with Drupal Console
Faster and Smarter Development with Drupal ConsoleFaster and Smarter Development with Drupal Console
Faster and Smarter Development with Drupal Console
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composer
 
Drupal
DrupalDrupal
Drupal
 
Drupal 8 - Improving your development workflow
Drupal 8 - Improving your development workflowDrupal 8 - Improving your development workflow
Drupal 8 - Improving your development workflow
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To Drupal
 
Rapid site production with Drupal
Rapid site production with DrupalRapid site production with Drupal
Rapid site production with Drupal
 
Face your fears: Drush and Aegir
Face your fears: Drush and AegirFace your fears: Drush and Aegir
Face your fears: Drush and Aegir
 
LuisRodriguezLocalDevEnvironmentsDrupalOpenDays
LuisRodriguezLocalDevEnvironmentsDrupalOpenDaysLuisRodriguezLocalDevEnvironmentsDrupalOpenDays
LuisRodriguezLocalDevEnvironmentsDrupalOpenDays
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architecture
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module development
 
Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)
Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)
Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 

Recently uploaded

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Drupal 8 cli

  • 1. Drupal 8 CLI Command line interface
  • 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