Navigating the Complexities of Drupal 8 If You've Been Living in a Drupal 7 World

Navigating the Complexities of Drupal 8 If You've Been Living in a Drupal 7 World

Authored by Ameex Technologies on 25 Feb 2019

For those who managed to get their way around Drupal 7, migrating to Drupal 8 might come as a challenge. As a Drupal developer, you have tackled different issues and won, managing to create complex modules from numerous PHP libraries, and solved complex business logic. However, your procedural understanding will no longer suffice in the world of Drupal 8.

Two experts, Toby Hagler (Phase2 Director of Engineering) and Ryan Loss (Developer), joined forces at DrupalCon Nashville to share insights on the novelties in Drupal 8, and tell us what ‘Symfony’ is, what is its purpose, and how it is a part of Drupal 8. For a better understanding, they have related everything to the Lovecraft mythos.

The Lovecraft Mythos

One of the common themes in Lovecraft’s cosmic horror stories is the trope - blue and orange morality. People tend to see everything in black and white (and some shades of grey), with a two-dimensional value system of good and evil. But a cat; that is a cute and lovely creature that loves to murder on a beautiful day, which means that it has a different value grid that’s sometimes referred to as blue and orange morality. Drupal 8 and Symfony kind of exist like that.

Drupal 8 is not hard – it’s different. Very straightforward at the surface, but complex and different beneath the hood. Toby and Ryan have made their best to teach us about the back-end concepts of Drupal 8.

Investigating: What’s New in Drupal?

There have been many changes in Drupal regarding controllers, routes, plugins, and services. You’ve moved to Drupal 8 and find out that a lot of changes make it feel otherworldly.

Classes

User-defined, custom data types, such as strings, integers, arrays, floats, enums, hashes, etc. Classes are made up of properties and methods, where properties are variables within the class, while methods are a particular type of function contained solely within the scope of a class. Classes can extend other classes (inheritance), implement interfaces, and implement traits. They can take on the features of different classes and keep on stretching to infinity. 

Objects

Object – a variable version of a class. A class is a data type, while an object is an instance of a class (like a node). 

The Introduction to Symfony Framework

Symfony is a mature PHP framework that’s been around for years, but if you want to utilize its powers, you must submit to its design patterns. Symfony is there to fight the chaos and forge it into something more universal across frameworks and platforms.
Symfony grants exclusive access to an autoloader that can build up a code cache and load only the services required. It can result in fewer resources allocated to Drupal, but we must first understand the Symfony framework.

Namespaces – abstract containers hold the logical grouping of unique identifiers (names). They limit the scope of your class to your module.

Annotations and conjurations – Annotations are there to help Drupal discover a particular plugin while scanning your module directory. 

Entities

Entities in Drupal 8 are things such as users, nodes, and media items. For example, a Drupal user is an object of the user class which extends the entity-based class. All content entities can have fields which are useful for tagging, making media searchable, and other metadata.

Fields can be added easily through the Admin panel as well as exported as a configuration that you want to add to a module.

Plugins in Drupal 8

Drupal’s plugin system is a vital back-end concept. Plugins are a type of class that provides a unit of functionality that is swappable and solves a single problem. Components of Drupal core, such as forms, blocks, or fields, have been designed to be pluggable, which allows you to reach in and change them if necessary. Plugins always have a plugin type, which is the central controlling class that extends and defines how a plugin is discovered and instantiated. Of course, you can still create your plugins if the right one is not available.

Understanding Routes and Controllers

The days of callback functions and hook menus are long gone, and URLs and paths to content have all been replaced with the Symfony framework of routes. Routes act as a switch box that routes any request. Routes and controllers are particular types of classes that handle the response to the request.

Services, Dependency Injection, and Events

In Drupal 8, Symfony introduces service-oriented architecture. Imagine a warren of tiny creatures, running around with their tasks and doing something for a master entity (sometimes working together to achieve something.) It’s how you can visualize this kind of architecture.

Service – a class that’s intended to do a particular task. 

Dependency injection – Arguments passed to a service in a module. You can inject whatever dependencies you want into it directly

Service container – When Drupal’s autoloader discovers all of the service classes, it puts them into a service container. It’s an index of all the services that Drupal knows.

Service types – Just like plugins have plugin types; services have types (like events.) Events are a regular service, but they’re not something that you call like one. It gets called automatically at one point of code execution.

Helpful Tools for Dealing with Drupal 8 Back-End

When developing Drupal’s back-end, these are the things that were found incredibly useful, and the presenters wanted to talk about:

  • SQL Pro (run queries directly, full UI for your database)
  • CLIs (run basic and repetitive tasks quickly, skip the UI)
  • Xdebug (pause and analyze function mid-execution, run methods on properties, stack tracing)
  • Devel (merging the UI and back-end; has Kint, Web Profiler, and generate dummy content)
  • Drupal itself (useful for understanding, learning, and implementing Drupal)

Want to learn more about Drupal 8? Do you need a developer that can help you prepare and migrate your site to the latest version of Drupal? Contact us today
 

RELATED TAGS

Blogs