Skip to main content

PHP Interface: Why do we need that

Object interfaces allow you to create code that specifies which methods a class must implement, without having to define how these methods are implemented. Interfaces share a namespace with classes and traits, so they may not use the same name.

Interfaces are defined in the same way as a class, but with the interface keyword replacing the class keyword and without any of the methods having their contents defined.

Advance Examples Which actually needed

This article is based on the O'Reilly article which is relevant to Drupal7 and some of it for Drupal8, but drupal did a lot of modifications since then, and I believe it's a good place to start with, but still should be modified to Drupal9 and on. from time to time I will fix this article and update it according to the last drupal version, you are all invited to send me remarks and suggestions.

These examples, I believe are most needed for the more advanced Drupal backend developer.

My development strategy recommendations are:

Patch creating process

A Module from drupal.org can be installed manually or with the composer tool, which supposes to be already installed on your server.

A Module is a software that needs to be maintained from time to time, it even has fixes for the current features, and sometimes new features, some of the major updates will come as a normal module update, and can be done via the upgrade page, but sometimes there is a need for fast push of small fix, this is called patch.

77 Tools For Drupal Developer

Use these development tools to help you create Drupal sites faster and with less effort.
If you have a favorite Drupal tool that is not listed, make sure you've checked every section of this document.
Still can't find your favorite?
Please add it using the format as other listings, similar to: Toolname (Free/Commercial. FOSS/Proprietary. OS Platforms.) - Description.

You can update us in the article comment section

 

Form Element 'table' with TableDrag and TableSelect

Building and rendering a table required writing a custom/dedicated theme function for most tables in Drupal 7.

Drupal 8 introduces a new element '#type' => 'table', which comes with built-in, optional support for TableDrag and TableSelect, and which requires no more custom plumbing for most use-cases.

Note: The following conversion example shows both TableDrag and TableSelect in a single table for brevity, but they are usually not combined in a single table.

Render API overview and Render Element

The main purpose of Drupal's Theme system is to give themes complete control over the appearance of the site, which includes the markup returned from HTTP requests and the CSS files used to style that markup.
In order to ensure that a theme can completely customize the markup, module developers should avoid directly writing HTML markup for pages, blocks, and other user-visible output in their modules, and instead return structured "render arrays" (see Render arrays below).

How to Send Mail from Module

Email support can be a very strong drupal capability.
You can create emails according to events, news, etc. with personalization and desired format and template.
In some cases, you need to define the email in a way that it will not appear as spam on the target email server.

Email on general drupal events like creating new articles are covered with the rules module and you don't need to program their email support.

Message Headers

Message Headers

An email consists of three vital components: the envelope, the header(s), and the body of the message. The envelope is something that an email user will never see since it is part of the internal process by which an email is routed. The body is the part that we always see as it is the actual content of the message contained in the email. The header(s), the third component of an email, is perhaps a little more difficult to explain, though it is arguably the most interesting part of an email.

Difference between IAAS, PAAS and SAAS

1. IAAS: Infrastructure As A Service (IAAS) is means of delivering computing infrastructure as on-demand services. It is one of the three fundamental cloud service models. The user purchases servers, software data center space, or network equipment and rent those resources through a fully outsourced, on-demand service model. It allows dynamic scaling and the resources are distributed as a service. It generally includes multiple-user on a single piece of hardware. 

How to Upgrade Drupal7 Module to Drupal 8/9

Since Drupal8/9 works very much differently than Drupal7, the module structure has changed, the files type supported changed and Drupal API also changed. so with many modules which are available for download, you can find separate versions for Drupal7 and Drupal8/9.
But in the case of a custom module, you would like to upgrade your own module.

The Drupal Module Upgrader is a Drush command that helps you update your modules from Drupal 7 to Drupal 8.

StarterKit Theme

While creating a theme for Drupal 8 or 9, the best practice was to subtheme the Classy core theme to ensure common CSS classes and the usual markup needed.
Thus it was imperative to call the Classy theme at runtime regardless of whichever custom theme you were using.
This dependency hindered the code updates on the Classy theme as any update would break backward compatibility.

How to Redirect A Page

Redirect needs were always important when developing with C, we remember how we use the Goto() command, and with Drupal 7 we had the Drupalgoto() command, but these options were deprecated within Drupal9 which become a fully object-oriented and object-derived system.

so how do we create Redirection commands?

There are a few options to do so, I will try to overview them all.

entityQuery simple and standard like a dynamic query

entityQuery allows developers to query Drupal entities and fields in a SQL-like way.

A Drupal site's tables and fields are never a 1-to-1 match for the site's entities and fields - entityQuery allows us to query the database as if they were 1-to-1. 

Much like you could write some SQL that returns all rows of table1 where field1 is 14, using entityQuery you can ask Drupal to return all entities of type "basic page" where the value of field_some_field is 14. 

How to prepare to Migrate if you are on Drupal 7

The Drupal security team will soon cease to provide security advisories, wavering the websites and cyber security.

Drupal 7 and Drupal 8 versions will get flagged as insecure in the 3rd party scans.

Drupal 8 already ended in November 2021.

Hence it is essential to plan and execute your Drupal 8 to Drupal 9 Migration or from any other version, before facing any security implications.

With the end of Drupal security support for the older versions, there would be many.

The expected release date for Drupal 10 is 14th December 2022.