Drupal Global Contribution Weekend 26, 27 January 2019
January 26, 2019 – 10:00 – 14:00 (MSK)
January 27, 2019 – 10:00 – 14:00 (MSK)
Hello everyone! My name is Ivan, I’m a Drupal developer, and I run a blog and YouTube channel about Drupal:
https://drupalbook.org
https://www.youtube.com/c/IvanAbramenko
Creating a social network on Drupal
Drupal: Pushing the Limits
Drupal is one of the best content management systems (CMS). In fact, it won the 2008 Best Open Source CMS and Best PHP Open Source CMS awards—twice! After about 8 years of development, Drupal has become one of the most powerful and versatile frameworks available. Its incredible flexibility is both its greatest strength... and its greatest weakness. Any functionality is possible—but where do you start? I’ve spent long days exploring various modules, their use cases, compatibility, bugs, and quirks, to confidently recommend what works.
Pre-configuration of a website for a social network on Drupal
In this lesson, I will preconfigure Drupal for a social network. I will install the following modules:
User profile in Drupal
Profile Page in Drupal
The profile page is the most complex and exciting part of any social network. I hope this will also be an engaging experience for you after reading this article. Drupal offers us several options for implementing user profiles. The first option available as a core module is the Profile module. This module is suitable if you want a very simple profile. But we're talking about a social network.
Developing modules for Drupal 7
In this section of the tutorial, I will demonstrate that Drupal is not just a CMS. We will explore what Drupal modules consist of, and we’ll also create a few of our own modules.
Drupal 7 - Working with DB via PHP PDO
With the transition to Drupal 7, we move to the new Drupal DB abstraction layer API, which is built on top of PDO. PDO has long been used in frameworks like Zend, as well as many other PHP frameworks. But everything seemed so convenient in Drupal 6 with writing plain SQL queries — so why do we need something new?
Let’s first understand what PDO is.
Working with Database in Drupal 7 - Lesson 1 - Drupal DB API
If you’ve written modules for Drupal 6, switching to the new Drupal 7 Database API won’t be too difficult. The new DB API is based on the PHP PDO extension, which gives it the ability to work with various databases like MySQL, PostgreSQL, MSSQL, and potentially Oracle. Whether it’s easier to use is subjective — getting used to the new syntax takes time, and writing SQL queries is still more familiar for many developers.
Here’s a brief excerpt from the official documentation:
Working with a Database in Drupal 7 - Lesson 2 - Database Configuration
The primary mechanism for defining a database connection in Drupal is the $databases
array in settings.php
. As the name implies, $databases
allows you to define multiple database connections. It also supports defining multiple targets. A connection is not opened (i.e., a connection object is not created) until a piece of code executes a database query for the first time.
Working with a Database in Drupal 7 - Lesson 3 - Static Queries (SELECT)
The most common form of a query in Drupal is a static query. A static query is passed directly to the database as-is. Only SELECT queries can be static.
Use static queries only for very simple operations. For more complex, dynamically constructed, or modifiable queries, you should use dynamic queries.
The simplest way to execute a static query is via the query method:
<?php $result = $conn->query("SELECT nid, title FROM {node}"); ?>
The preferred approach is to use the procedural wrapper:
Working with a Database in Drupal 7 - Lesson 4 - Dynamic Queries (SELECT)
We’ve now reached perhaps the most exciting part of Drupal’s Database API: dynamic queries. These are called "dynamic" because Drupal appends the query string on the fly. All INSERT, UPDATE, DELETE, or MERGE queries can be dynamic. SELECT queries can be either static or dynamic. However, it is recommended to use dynamic queries even for SELECT operations.