Articles

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.


In this article, we will not write code, but prepare to write code. To do this, we will install Drush. Drush is a console utility that allows you to perform many routine operations with Drupal: update modules, upload / download configuration, backup and much more.
If you use Open Server as a web server for development, then this instruction will suit you:
1. Install the server itself. You can download it from the author's website open-server.ru. Installation and documentation there.


Everything we disassembled before, everything was like the previous versions of Drupal. But with the development, everything is different. Although visually Drupal looks the same as Drupal 7, inside Drupal consists of Symfony components, its components, as well as many libraries. Therefore, you have to deal with the new plugin system, deal with OOP in PHP.
To begin with, we will start with the pretty familiar things Drupal hooks, then we will figure out how Drupal works with pages (route), add a new page, consider how Drupal processes requests.


In order to have a catalog of categories in your store on Ubercart, you need to enable the catalog module:
Before including the Catalog module, it is better to immediately include the Product, Store, Country modules.
After installation, we will have a dictionary of our product sections Catalog:
/admin/structure/taxonomy


Ubercart installs as a regular module:
The first block of modules are required for installation:
Cart - cart module.
Country - settings module for a specific country.
Order - module of orders.
Product - product settings.
Store - the main settings of the store.
