How a subscriber is different than a listener, and what a 'code smell’ is

Description

Collection: Drupal 8 Developer PrepChapter: How to Work With Symfony Components, Part 2

When you have multiple listeners that will always be bundled together, or that will take the same parameters no matter which application will use them, it makes sense to refactor to us a ‘subscriber’ instead. As we discuss this, we also explain what a ‘code smell’ is.

Transcript

Okay. So this is good. This is good abstraction so far, but there is one thing that still kind of seems like it's in the wrong place.

If we go back to front dot php, it's the fact that we are setting the priority here of this listener inside of our front dot php file. Now, because the ContentLengthListener is something that will act the same for any application pretty much, it makes sense to run it before all of our other listeners. So that's something that doesn't really belong in our front dot php file.

It's not something we want to copy over and over again for every front controller that we have. Now, it's just a few characters so it doesn't seem like it should be that big of a deal. But this is an example of something called a Code Smell.

It's when our code kind of looks like it may be off in some way. We can deal with how it's structured now but it might be an indicator of a larger problem or issue with our architecture that's going to make it harder to extend later on. So that's what this is.

This collection will not only prepare you to work with and understand Drupal 8 under the hood, it will increase your skills and relevance as a developer. We cover Object Oriented Programming (OOP), how to use Composer, what the Symfony framework is and how to use its various components, plus lots, lots more. For developers really wanting to modernize their skill set, this is a great place to start.

Before watching this series, you will need a web environment with Drupal 8 installed. Follow the videos in the Setting Up a Web Environment With Drupal to set up a web environment. In the series, we use a couple different versions of Drupal 8 and provide instructions for installing each one so you can follow along with the series exactly. You can also use the latest version of Drupal 8, but there will be some slight differences between what you see in the videos and how you would put what you see into practice, but working through those differences can be excellent for learning.

Some of the key points we'll be covering include:

How to build basic module scaffolding in Drupal 8

How Object-Oriented Programming (OOP) works and how to apply what you learn to coding in Drupal 8

How to work with Symfony components included in Drupal 8

How to use Composer to keep track of code dependencies and leverage a huge library of PHP components

Who this collection is for

This collection is mostly for Drupal developers who want to upgrade their techniques to work with Drupal 8. Because many of these techniques are applicable to PHP coding in general, it can also be useful if you simply want to develop your PHP skills and wrap your mind around object-oriented programming.

Prerequisites

You will get the most out of this collection if you are comfortable with procedural coding in PHP. We will make references to how code works in Drupal 7, so it will be helpful if you have some Drupal coding experience in particular.

It looks like there might be an issue playing videos in this browser. We're working on better cross-brower experience, but in the meantime please try the latest Chrome or Firefox browsers. Or, you may be able to watch the video directly without progress tracking or transcript: