It will be located inside the /src/Command/Generate folder as it is a code generation command. The main class is PluginQueueWorkerCommand, as it will be in charge of registering the Drupal command, that is, informing Drupal Console of the existence of a custom command. Let's check the generated module files according to their importance. This will generate a bunch of files and directories with the base for the command. ![]() The command line would be: drupal generate:command \ We'll use a class called PluginQueueWorkerCommand, and the command will be generate:plugin:queue. In this case we want to generate a command in the 'drupal_console_queue' extension of type module. Options are not mandatory, if not provided Drupal Console asks for them when run. generator Adds a Generator class in charge of handling the scaffolding. container-aware Check a Drupal site is installed. interact Adds an interact command, in charge of processing input params. ![]() class=CLASS The class that defines the commands (it should end on 'Command'). extension-type=EXTENSION-TYPE Extension type (module, theme, profile). The command's options are: -extension=EXTENSION Extension name Therefore we will use the following command: drupal generate:command To create our own Drupal Console command what better way to start than by using Drupal Console to generate the initial code. This is what is called scaffolding: the action of generating the code and directories needed to start a project or component. You can install Drupal Console Launcher to execute Drupal Console globally without using the complete path ( vendor/bin/drupal) on each project. As many (if not all) Drupal projects, we use Composer to add it as a dependency. Drupal Console installationįirst you'll need to install Drupal Console. By means of the Queue API we can create a queue, insert the received data in this queue, and that later a QueueWorker would recover and process the data. Let's imagine that our web requires to make a process on certain data, for example on data that are received from time to time from external sources. A QueueWorker is in charge of processing the elements of a Drupal 8 queue API queue. ![]() Specifically, in this practical example we are going to create a Drupal Console command that will allow us to generate the code base for a QueueWorker. In this way you can generate code with the base for a new module, a new form (you can even tell him what form elements you want!) or a new Drupal service.īut in this article we will not talk about generating code, but create a new Drupal Console command for Drupal 8. Some examples of commands: drupal generate:module # Generates base code for a new module.ĭrupal generate:service # Generates base code for a service.ĭrupal generate:form # Generates base code for a form. This is where Drupal Console comes in: it offers commands to generate code for many of the tasks you may need to develop. ![]() In version 8 Drupal has become much more object-oriented, which is good, but in return it is more complex to do certain tasks that were previously done by implementing one or two hooks in the. Drupal Console eases Drupal 8 development in different ways, but the one we're interested in in in this article is code generation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |