Contents
Drupal
A CMS for complex sites: custom modules, routes, forms, entities, blocks and Twig templates.
1.Getting started
- What Drupal isWhat Drupal is, how it differs from a framework, what is done in the admin panel and what is written in a module, and what the course builds.
- InstallationInstalling Drupal through Composer: creating the project, installing the site with a Drush command, starting the built-in server and logging in.
- Project structureThe folders of a Drupal project: web, core, modules, themes, sites and vendor — what they hold and where your own code goes.
- DrushThe Drush console program: how to run it, the main commands, rebuilding the cache and installing ready-made modules.
- Core conceptsThe Drupal vocabulary for a developer: nodes, content types, fields, taxonomy, blocks, views and entities.
2.Module and pages
- The first moduleCreating a Drupal module: a folder in modules/custom, the info.yml file, enabling the module and checking that it works.
- RoutesThe routing.yml file in a Drupal module: the route name, path, controller, title and access requirement; how to link to a route.
- ControllersA controller in a Drupal module: where the class lives, how it is tied to a route, what a method returns and how to return JSON or a redirect.
- Route parameters and accessParameters in a Drupal route path, validating them, automatic loading of a node and access conditions in the requirements section.
- Menu links, tabs and action buttonsHow to show a Drupal module page in a menu: the links.menu.yml, links.task.yml and links.action.yml files.
3.Output and theming
- Render arraysRender arrays in Drupal: properties with a hash sign, nested elements, ready-made elements — list, table, link — and safe text output.
- Twig templates and hook_themeYour own template in a Drupal module: declaring it through hook_theme in the module file, the file in the templates folder, rendering it from a controller and Twig syntax.
- Libraries: styles and scriptsAttaching CSS and JavaScript in a Drupal module: the libraries.yml file, the attached property, the attach_library function and Drupal.behaviors.
- Themes and template overridesYour own Drupal theme: creating it with the generate-theme command, the info.yml file, overriding templates, template name suggestions and preprocess functions.
- Translating stringsTranslatable strings in a Drupal module: the t function, placeholders, plurals, the TranslatableMarkup class and translation in Twig templates.
4.Module logic
- HooksDrupal hooks: what they are, the module file, reacting to a node being saved, altering another module's form and class-based hooks in Drupal 11.
- Services and dependency injectionDrupal services: your own class in the src folder, registering it in services.yml, getting a service in a controller through create and in hooks through the Drupal class.
- Events and subscribersSymfony events in Drupal: a subscriber class in the src/EventSubscriber folder, registering it in services.yml with the event_subscriber tag, and priorities.
- FormsThe Form API in Drupal: a form class in the src/Form folder, the buildForm, validateForm and submitForm methods, a form route and messages to the visitor.
- ConfigurationDrupal module settings: defaults in config/install, the schema in config/schema, reading and writing, and how configuration differs from state.
- The settings formA Drupal module settings page: a class based on ConfigFormBase, a route in the panel, a menu link and the Configure button in the list of modules.
- PermissionsYour own permissions in a Drupal module: the permissions.yml file, checking in a route through _permission, checking in code through currentUser, and node access.
5.Data
- Entities: loading and fieldsThe Entity API in Drupal: entity storage, loading a node by number, reading field values, references to other entities, changing and saving.
- Entity queriesFinding nodes in Drupal with an entity query: conditions, sorting, limiting, rendering a list of articles, creating and deleting entities.
- A custom blockA block in a Drupal module: a class in the src/Plugin/Block folder with the Block attribute, the build method, placing it in a theme region, block settings and services.
- PluginsDrupal plugins: how the system finds classes by folder and attribute, attributes and annotations, a field formatter example and other plugin kinds.
- The databaseA custom table in a Drupal module: hook_schema in the install file, inserting from a form, selecting, updating and deleting through the query builder.
- The cacheThe Cache API in Drupal: the cache property of a render array, tags, contexts and max-age, caching your own data and invalidating by tag.
6.Growing the project
- JSON:APIDrupal data as JSON: the core JSON:API module, addresses of collections and single nodes, filters, sorting and enabling write operations.
- Custom Drush commandsA Drush command in a Drupal module: a class in the src/Drush/Commands folder, the Command, Argument and Option attributes, and terminal output.
- Cron and queuesScheduled tasks in Drupal: hook_cron in the module file, running the scheduler, a task queue and a QueueWorker plugin.
- Moving configuration and deploymentDrupal configuration management: export and import with Drush commands, the sync folder, the workflow and the deployment steps on a server.
- Updates: hook_update_NDrupal module updates: hook_update_N functions in the install file, changing a table and settings, the drush updb command and updating core through Composer.