📜 ⬆️ ⬇️

Getting started with Drupal: a complete practical guide (part 1)

Hello!

I bring to the court habrabschestva translation of a wonderful article Getting Started with Drupal: A Comprehensive Hands-On Guide . This material is an indispensable guide for novice drupalschiki, because it covers not only the installation and basic principles, but also two of the three "whales" of Drupal-site building - Views and CCK. The best part is that the whole article is devoted to the practical creation of a useful site (bulletin board). Right, in the times of Drupal 4.7, when I was just starting to get to know him, one could only dream of such detailed and intelligible guides.

Let me briefly announce the drupalschik who worked on translation and localization: Ch , graker (initiator of the translation), iHappy (localization of screenshots), kyky (your humble servant), mak-vardugin , P.Selfin , trubinovskaya , vgoodvin .

Getting started with Drupal: a complete practical guide


Drupal (Drupal) - is a popular content management system with open source. Because of its powerful functionality, developing complex websites on Drupal is much easier than writing them from scratch. Not surprisingly, thanks to the large community of users and a huge number of modules, we hear about Drupal more and more often.
In this guide, we will in practice discover Drupal for ourselves and create a website with a new content type and pages for displaying it.
Ready? Immerse yourself in an extremely powerful content management system!
')
Tasks

By reading this manual, you:

What we will do

We will develop a site in Drupal with a vacancy notice board where visitors can add vacancies and projects. Our goal is that you start building sites right away, and not just read how to do it.

Why Drupal?

First, we briefly consider what advantages (and disadvantages) Drupal has, so that you can decide whether this CMS is right for you .

Virtues

Open source code. Yes, Drupal is open source, which means that all the advantages of open source software are available to you.

Configuration flexibility. The main advantage of Drupal lies in its flexible architecture. You can use it to build sites of any type: from social media sites that allow users to post and vote for their own content, forums and sites with vacancies to galleries or publications of designers' portfolios. Drupal will perfectly cope with the task (of course, for this you will have to work a little).

Numerous and competent developer community. A large, vibrant and open community of users and developers has developed around Drupal. This means you have access to excellent modules, timely bug fixes, and kernel updates, as well as an endless stream of documentation and manuals online.

Modules Drupal has developed a huge number of modules that extend its original functionality (we’ll talk about what a module is a bit later).

Ease for developers. As a web developer, you will not feel the limitations when working with Drupal. After all, Drupal was developed taking into account the needs of developers. The mistake of some basic CMS is an excessive emphasis on the user interface, which often entails a lack of attention to the needs of those who, in fact, will develop and promote the system in the future. But with Drupal it is not.

Built-in caching system. Drupal has a built-in cache system that can reduce server load and reduce page generation time . Caching avoids complex database queries, which improves server performance.

Decent built-in search engine. Unlike other CMS, Drupal has a very good search engine implemented at the kernel level. Of course, it cannot compete with search services like Google Search , or Yahoo! Search BOSS , but nevertheless quite suitable for work.

disadvantages

Long learning process. Yes, it is a fact that the study of Drupal is given somewhat more difficult than the study of other CMS. I would not recommend Drupal if you want to make the first site after a week of dating. It will take you more than one month to truly understand Drupal, and as many more to create the first full-fledged site. However, it should be noted that you can create a small website in less than a day (this is what we are going to do in this guide).
Difficulty for non-developers. Since the needs of developers are at the forefront, those who are not very familiar with information technology will need some time to get used to Drupal. This means that it will be difficult for professionals who know web development only superficially to create (or even administer) websites in Drupal.
Complex interface. The administration interface of the site in Drupal is somewhat difficult to understand; in general, it is not as user friendly as it could be. (However, this will change soon).

Drupal vs WordPress

Wherever Drupal is discussed, there always arises an overwhelming desire to compare it with another leading open web platform; usually this is wordpress .
And wherever you may assume that WordPress is not a full-featured CMS, but just a blogging platform - a heated discussion will always be waiting for you. I myself use both CMS, but sometimes WordPress capabilities are simply not enough .

In other words, if you make a serious resource with registration, authentication, permission sets and roles, for example, an Internet shop, forum or website with video and audio materials that users add themselves, it makes sense to use a more serious CMS than WordPress.
I would not recommend you to use Drupal if a client needs only a blog or a simple website with a portfolio consisting of several pages and basic content: such sites are faster and easier to do in WordPress. Drupal for this is clearly unnecessary.
Another important argument against using Drupal is an interface that is not easy for inexperienced users to understand. This is a strong argument for WordPress.

Sites working on Drupal

To inspire you, I will list several sites in Drupal.
Mozilla
Mozilla, the company responsible for Firefox , uses Drupal in almost all of its web projects. The official websites of Mozilla and Spread Firefox are made in Drupal.
Mozilla
Spread Firefox
Spread Firefox
Ubuntu
The official site of Ubuntu , the popular Linux distribution , the operating system that runs on many servers, is also made on Drupal. Note the size of this site and the number of content types and features; Soon you will understand why Drupal was chosen for Ubuntu.
Ubuntu
Need more examples? Then look at these great Drupal sites .

Download and install Drupal

In this guide, we will use the latest stable release of Drupal 6 ; Download it from here .
Download Drupal

Install Drupal on XAMPP

Here we will install Drupal on your computer, but if you want to put it on a real server, the process will be similar.
To install Drupal on a local machine, you need a server platform such as XAMPP or WAMP . Do not be alarmed if you have never heard of them - it is very easy to use them.
If you do not have a local web server yet, install XAMPP right now .
Below is a link to a simple tutorial for authorship by Jacob Gübe (founder and chief editor of Six Revisions ), which you will very quickly install and configure XAMPP (written for WordPress, so follow only the first part, steps 1-26, keeping in mind , that you are not installing WordPress, but Drupal):

Later in this guide, we assume that you are using XAMPP, so if you choose another server package, you may have to slightly change the installation process.
Copy the Drupal files to the XAMPP directory

Copy the package with Drupal, which you downloaded earlier, to the xampp \ htdocs directory. Unzip the files and rename the folder to drupal for easy navigation.
Now go to the xampp \ htdocs \ drupal \ sites \ default folder.
Go to xampp \ htdocs \ drupal \ sites \ default

Create settings.php

Make a copy of the default.settings.php file and rename it to settings.php.
Make sure that you have not deleted default.settings.php , otherwise the installation of Drupal will fail with an error; This is one of the most common mistakes made by novice developers at Drupal.
Do not delete default.settings.php!

Creating MySQL Database

Drupal for data storage uses MySQL . So we need to pre-configure the MySQL database. To do this, we use phpMyAdmin - a web interface for convenient administration of MySQL databases (it is already included in the XAMPP distribution).
Access the phpMyAdmin page in your browser at:
localhost / phpmyadmin
PHPMyAdmin

In this example, I called the database db_drupal . You can grant the superuser ( root ) all privileges to work with the db_drupal base, so that he can read, write and change data in the database. However, using a root account on a working site is not a good practice . It is best to create a separate user for this database and give him only the necessary privileges. Now we will do it.

Creating a separate MySQL user for the Drupal database

In our example, I will create a new MySQL account and call it drupal_user . For work sites, however, it is a good idea to use a non-obvious, random username to reduce the likelihood of hacking during a brute force attack.
And certainly do n’t use a root account , as most hackers will try it first. The root user in MySQL has super-privileges and has access not only to your drupal_db database, but also to other databases. (By the way, a good option is to delete the root user altogether and not use it anywhere. You can create a pseudo-root user, but about this some other time).
To create a new MySQL user, go to the phpMyAdmin home page, and then click on the “Privileges” tab.
Now click “Add new user” and fill in the input fields with the necessary data.
Add MySQL user

Add MySQL user
While you are working on a local machine (that is, Drupal is installed on your computer and is running on XAMPP), you can select all available privileges, but it is highly recommended to install only those on the production server that are really needed by the user drupal_user.
For our example, I chose only those privileges that I want to grant to the user drupal_user.

User privileges
This concludes our work with MySQL and phpMyAdmin.

Localization Drupal (from translators)

For the installation process to coincide with the illustrations in this guide, you need to install the Russified version of Drupal. For this you need to download his translation. Translations of Drupal and its modules into Russian are on the site Drupaler.ru . To download the translation of Drupal himself, go to this page , fill out the form as shown in the picture and click "Export".
Export translation from Drupaler.ru

Then unpack the downloaded archive in the same directory where Drupal was unpacked a little earlier.
Translations for additional Drupal modules are also on Drupaler.ru. Since we will need the CCK and Views modules later in the guide, download their translations right now from the CCK Translation and Translation Views pages.

Install Drupal using the installation wizard

So, we enter in the address bar of our browser the following URL:
localhost / drupal
If you have not forgotten to rename the unpacked directory with Drupal to “drupal”, everything should work. If you have forgotten, replace “drupal” in the URL with the name of the folder you specified when unpacking the Drupal files in htdocs.
As soon as you navigate to the URL above, you will immediately see the Drupal installation menu. You can select the desired interface language Drupal on the first page. Please note that this option can be changed later from the admin panel. We will continue the installation in Russian, so let's choose "Install Drupal in Russian."
On the next screen, Drupal will check if your server (in our case, the local machine) is able to work with Drupal. If your server doesn’t have enough applications for Drupal, an error message will be displayed.
Next you will see the database configuration screen. Here you need to provide the information that you used when creating the drupal_db table and the drupal_user user.
Database configuration
In the same place, on the database settings screen, click on “ Advanced Settings ” and you will see an option called “ Table Prefix ”, which allows you to assign a specified string to the name of all Drupal MySQL tables (eg blackjack _drupal_table). I recommend that you specify a random prefix that only you can understand; this caution will help reduce the risk of an attack on the database using SQL injections.
Set the table prefix
If all the previous steps were performed correctly, Drupal will start installing the necessary modules, after which you will be redirected to the site configuration page .
Site configuration
The configuration parameters are intuitive, so I will let you enter all the necessary information yourself.
Site configuration

Setting clean links

One of the options that may be unfamiliar to you is called “ Clean Links ” and is located in the “Server Settings” section. The links generated by Drupal by default are non-intuitive and look something like localhost / index.php? Q = 21 .
When pure links are included, the URLs look nicer, easier to remember and help improve SEO . For example, localhost / events .
For clean links to work, it is required that mod_rewrite (an Apache module) be installed on the server. Most likely, it is already installed.
If mod_rewrite is not installed or not started (which is unlikely if you have an Apache server), Drupal will generate an error and the use of clean links will be unavailable. This will not prevent us from creating the site, but for the reasons described above, you should include clean links as soon as possible.

Installation completed

If you followed the manual correctly, you’ll see this screen:
Installation completed

Do not worry if the mail () function error appears : it occurs because we use XAMPP on the local machine and simply did not configure the mail server, therefore Drupal will not be able to send letters to administrators.
When you work with a real server, these things will already be pre-configured (unless you are doing your own web server, which has not yet been configured).

Go to the admin panel Drupal

Let's go to the admin panel of Drupal. As soon as you enter the new site at localhost / drupal , the following page will appear:
Welcome to Drupal
Enter the admin area by clicking on the "Manage" link.
Now that you have installed Drupal, it's time to discuss the concept of modules.

What are Drupal modules?


Modules are Drupal extensions that add additional functionality to it.
For example, Drupal comes with a pre-installed module called "System". In fact, Drupal is a set of kernel modules that are developed and maintained by the project team. The “System” module is one of them, Drupal cannot work without it.

How to add Drupal modules

In addition to the kernel modules that make up Drupal, you can download additional modules from the official repository repository . In addition, after gaining development skills on the API modules of Drupal , you can create your own modules.
After you find the module you need, download it to your computer.
Then you need to move the unpacked module to the drupal \ sites \ all \ modules directory.
By default, there is no folder for modules , so you need to create it manually. Create a modules folder in drupal \ sites \ all.
A good practice is to keep the downloaded modules separately from the ones that come with the Drupal distribution by default, so do not put additional modules in drupal \ modules .
Where to store modules

Installation of an additional module: CCK module

CCK (Content Construction Kit - Content Builder ) is a very popular Drupal module that allows you to create different new content types. Let's practice installing modules on the example of CCK, especially since we will need it later.
First, download the appropriate version of CCK . Then unpack the archive into drupal \ sites \ all \ modules; in the same folder, unpack the archive downloaded earlier from Drupaler.ru with the translation of the CCK module.
After downloading and placing the CCK module in drupal \ sites \ all \ modules, you need to enable it in the administration interface of Drupal. Go to Site Construction> Modules (localhost / drupal / admin / build / modules). Here you will see the CCK module *. Turn it on. You can also enable the CCK submodules if you need them (later, when we start working with CCK, we will do so).
Module installation

* - according to the tradition established in ancient times, the module, everywhere and everywhere called CCK, is called Content in the list of modules.
Congratulations! You have just installed the Drupal module.

Drupal administration pages: crash course

There are two options for viewing the administrative sections of Drupal:
  1. According to the tasks.
  2. By modules.

If you select the “ To Tasks ” display, the page will be organized according to various administrative tasks.
For example, if you organize the "Tasks" page under the "Content" heading, you will see all the tasks related to working with the content. “Content”, for example, allows you to view, edit and delete materials, a “Publish Settings” control their behavior and display on the site.
Each task has a short description called to help you understand its purpose.
If you choose the “ By Modules ” display, then the links will be organized by modules.
For example, in the “By Modules” display under the heading of the “System” module you will find the items “Setting access rights”, “Clean links”, “Modules” and so on.

Curve study interface admin

You can get used to the administrative interface of Drupal for a very long time ; however, there are many additional modules that greatly facilitate the work with the admin.
I advise you to install the Administration menu module, which adds to the top of all pages of the site a drop-down navigation menu, visible only to the administrator.
Admin drop-down menu

Customize the main page

It's time to act. Let's create the main page. To do this, we will add the first page type material to the site. Go to the menu Content> Create Content> Page (localhost / drupal / node / add / page).
Add a page

Menu options

The theme that Drupal uses by default displays the navigation menu in the upper right corner. The settings in the Menu Options section determine whether to include a link to our page in the navigation or not.
If you want to add a link to the main page to the main navigation menu, select "Main links" in the "Parental item" drop-down menu.
The " Weight " option allows you to organize the order of display links. Links with less weight will be displayed first, because they are "easier".
So, for example, if the “Homepage” link has a weight of 0, and the “About Site” link is 5, then the “Homepage” item will be shown first, because it is easier.
If the “Homepage” link has a weight of 0, and the “About Site” link is also 0, then Drupal organizes links in alphabetical order. Since the weight is the same, the “Home” item will be shown first.
In our case, we leave the weight of the “Main Page” unchanged (by default, the weight is zero).
Menu options

Input format

The selector in the "Input format" section allows you to select the content input method.
The Filtered HTML format restricts the set of HTML tags that can be used in the text by filtering dangerous HTML elements like & lt; script & gt; that can be used to attack the site visitor’s browser.
Use the Filtered HTML format if the site administrators are not familiar with HTML.
And for developers should use the format of Full HTML . Using this format assumes that you are familiar with HTML.
Input format

Revision Information

If only one person is engaged in creating content on your site, this option is probably not useful to you (unless you are very forgetful).
If you are working with a team of users adding materials and want to save different versions, keep a log of content changes and make notes about the nature of these changes - the "Editing Information" section will be very useful for you.
In addition, with the checkbox “ Create a new edition ” checked, the old version of the material will be saved in case you want to return to it.
Revision Information

Comment options

These options allow you to enable or disable visitors' comments for this material. We probably do not need comments on the main page, so I chose the item " Disabled ".
Comment options

Author Information

In this section you can change the name of the author and the date of publication.
You do not need to fill in these parameters every time - Drupal will do it himself, provided that you have not changed them.
Author Information

Publish Settings

This section sets the publishing options for the material.




Look at the main page

And here is our main page; for now it is very simple, but do not worry, soon we will complicate it.
Home page

What do we do next

Next we will make a vacancy bulletin board , filled with users.
In the process of its creation, we will work with custom types of materials, views, views and other means of developing sites on Drupal.

What is a node in Drupal?

Before proceeding, it is necessary to discuss one of the most incomprehensible topics for beginners - the concept of nodes.
A node is a basic element in the content structure of Drupal. Simply put, if you imagine Drupal building, then the nodes will be building blocks. Each part of the site content is a node - be it a page, posting in a forum, an article, etc.
Remember that the administration and user profile pages are not considered nodes, since they are generated by the system and not by users.
Noda is the most important concept that you must understand if you plan to develop complex websites on Drupal. Despite the fact that the meaning of the nodes is often incomprehensible to beginners, they give the developer on Drupal incredible flexibility in creating and configuring sites.
To see this in the example, let's go to the main page created earlier. Pay attention to the address bar of the browser, it will indicate something like this (if the clean links are disabled, the address will look different):
localhost/drupal/node/1

In the address you will see the word "node"; This means that this page is a node.

Creating a new type of material in Drupal

Creating a new type of material is a great way to customize a site for your needs. For each type, you can define a display method, assign access rights, attach additional properties — the possibilities are endless.

Create a type of material "Vacancy"

Let's make for our site a message board about vacancies. Users will post jobs and projects, such a small Craigslist (note of the translator: www.craigslist.org is a service for posting vacancies and resumes).
For each vacancy, we will need the following fields:

Working with custom material types in Drupal is easy. First go to Administration> Material Types> Add Content Type .


Almost all elements of the page for adding a new type of material are provided with explanations. I consider it necessary to talk separately about the element "Type". Type is the machine name of a new type of material used in more complex designs.
In our case, for jobs we will set the machine name for the type of material “job”. This is a very important point: in the future, when you become master ninja Drupal and want to make complex changes to your site, for example, change the way ads are displayed, you will need to create a file named node-job.tpl.php (this is already beyond of this manual).
Now fill in the “Name”, “Type” and “Description” fields, and we will move on.

Form properties

In this section, you have the opportunity to create and configure a form for entering vacancy announcements; users will see it when they post vacancies.


Setting up the publishing process

The publishing process settings contain the basic parameters for publishing the material. If you want the vacancy to be published without a preview by the administrator, tick the “Published” option.


Continue to customize the publishing process. In the “Comment Settings” section you can set various options for commenting vacancies. If you want visitors to comment on jobs, include comments. Do not want - turn off.

We create the type of material "Vacancy"

It's time to click "Save" and thus complete the creation of our first type of material. If you followed the instructions, “Vacancy” will appear in the list of content types (next to the page, article, and so on).


Configuring Content Types with CCK

So, we have our own type of material. Now we need to customize the form for adding vacancies using the extremely useful module - CCK.
CKK is, as a rule, the first module that sophisticated developers put on a new website. It is so important that it will be embedded in the core of Drupal 7 , after which you no longer have to download it manually.
By this time you should have installed CCK as described in the module description at the beginning of the manual.

Enable multiple CCK submodules

To get started, go to Administration> Construction> Modules .
In the CCK section, you will see a list of submodules. Some of them are already included by default, and some are not. Why?The architecture of Drupal is extremely modular, and this allows us to use in the development only those tools that are really needed. Module developers are advised to group them according to their functionality, as a result of which modules are less bulky and more economical.
As the site administrator, include only those modules and sub-modules that you really need.
Now let's include a few CCK submodules that we need for the vacancy form.
Here are the sub-modules that need to be included:
CCK

Since users may be required to enter fractional numbers (for example, the required work experience in years), we will need to enable the Number sub-module.
We also need the Option Widgets module, which allows you to add different data entry elements, such as checkboxes, switch groups, and so on.
Each of these sub-modules depends on the Content module: you cannot enable them while Content is turned off.

Add fields to the form

Did you include CCK submodules? Great, it's time to customize the posting form.
Go to Administration> Content> Content Types , then click on the “Manage Fields” link in the “Actions” column for the “Vacancy” material type. This is where we will add new fields to the form.


First, I will add the “ Departmentfield , giving the user the opportunity to select from the drop-down list the department in which the vacancy arose (development department, finance, interface department, IT and marketing).



After clicking the "Save" button, you will be redirected to a page where you can finally adjust the "Department" field and list its valid values.



The next field - “ Experience", The user can enter fractional numbers into it (for example, 3.5 years).

In the “ Help text ” field, add a hint on how to fill the field correctly so that visitors enter the correct values.

In the " General Settings " section you can limit the field value. For example, if you specify 2.3 in the Minimum field, then when you try to post a job with experience 1.4, the user will receive an error message.

The last field in the type of material "Vacancy" - "Wages". This is an integer, for example, 50 000 rubles.

In the general field settings, specify 0 as the minimum to prevent negative values ​​(for example, -1200). Why not specify a value greater than zero? Because zero salary means that this job is not paid.
After creating all the fields, their list for the “Vacancy” material type will look like this:
CCK
Dragging the cross icon to the left of the field names, you can change the order of their display in the form of adding vacancies.

Create multiple vacancies

Before we move on, create a few vacancies by going to Create Material> Vacancy . We will need their data in the next part of the manual.

CCK is a very powerful tool.

Here we worked with the simplest CCK fields, but this module provides much more serious means of organizing content. For example, you can install the ImageField module so that users can post images (for example, let employers post pictures of the workplace).
If you need additional CCK fields, check out this list .

Continued .

Discussion on drupal.ru

Source: https://habr.com/ru/post/103600/


All Articles