Articles

Configuration in Drupal is the basis for all settings of content types, fields, configuration forms and variables. With the help of configuration we can transfer changes from one site to another, develop different features at the same time and without interfering with each other.
Configurations can be uploaded to YML files and added to the Git repository, so you can commit your changes in site settings and transfer the changes to Dev or Live. The idea of configuration in Drupal is similar to how the Features module works:


In this article we will continue to understand Form API in Drupal 8 and make a multistep form. We have already created the usual configuration form for the module, the multistep form is created in a similar way using $form_state to store data between the form steps.
Examples of code can be found at github:
https://github.com/levmyshkin/drupalbook8
For a multistep form you need to add a form class:
/modules/custom/drupalbook/src/Form/MultiStepForm.php


In one of the previous lessons we have learned what hooks are, in this lesson we will work with hook_form_alter() hooks in practice and add functionality to the existing form.
Examples of code can be found at github:
https://github.com/levmyshkin/drupalbook8
In this lesson we will start to look at hooks in practice, later on we will return to hooks and look at a couple of other examples. For now, let's start with hook_form_alter().


In this tutorial, we will deal with the Drupal Form API and create a settings form for the module. We have already created modules for displaying the page and block, let's now create a configuration form in which we will store data for connecting to a conditional service. Let's say that we need to store the API Key and the API Client ID on the site, for example, for the Google Maps API.
Code examples can be viewed on github:
https://github.com/levmyshkin/drupalbook8


In this tutorial, we will look at how to output blocks programmatically through a custom module in Drupal 8.
Code examples can be viewed on github:
https://github.com/levmyshkin/drupalbook8
Let's start by adding a file containing a PHP class, this is how blocks are created in Drupal through a custom module. The process of creating the file is the same as the class for the page, as we did here:


We can use the parameters in the URL for routes. They work just like contextual filters in Views. We can for example pass in the URL the ID of various entities, text strings or sequential ID separated by comma or pluses. In this lesson, we will pass the ID of the node and display the title and body of this node in the content.
Code examples can be viewed on github:
https://github.com/levmyshkin/drupalbook8
Let's add route to our drupalbook.routing.yml module file:


As you learn the Drupal API, you will often need to refer to the main documentation at https://api.drupal.org. This is the automatically generated Drupal documentation. It contains all the information about each function, class, method, where they are defined, where a brief description is used. Also on this site there is API help, I advise you to familiarize yourself with each of the sections:


In this lesson, we will expand the capabilities of our module and create content that will be available only to registered users or users with a specific role.
Code examples can be viewed on github:
https://github.com/levmyshkin/drupalbook8
Let's start by adding a new YML file right in our drupalbook.permissions.yml module folder:


Let's start creating our module with a little ordering. Let's continue to separate custom and contributed modules. In Drupal modules are in the / modules folder. Now we do not need to put them deep into /sites/all/modules, although readme says that this should work, use the /modules folder after all. Inside the /modules folder, we will create two custom and contrib folders. The contrib folder will store additional modules from drupal.org, and our custom modules will be stored in the custom folder.
English subtitles:


This article is intended to familiarize you with Drupal, we will write code examples further, after adding our custom module.
