PHP Service Classes
FreeIn this course, we're going to continue on from the Introduction to Object-Oriented PHP series. We're working on the same spaceship project: it has ships, you choose them, then they engage in epic battle!
In an editor, far far away, you'll see a simple application that runs this: index.php is the homepage and battle.php does the magic and shows the results. In the first course, we created a single class called Ship
, which describes all its properties—it's like a container for one ship's details. In this tutorial we're going to replace our flat functions and create a BattleManager
service class to provide the methods we'll need to do that.
What's New in Drupal 8
CourseThis video was part of a series of presentations produced in anticipation of Drupal 8's official release. For information about configuration management based on official releases of Drupal 8, view tutorials in our Configuration Management series.
[# card #]
nid: 2458
title: Config Management series
[# endcard #]
This presentation introduces the Drupal 8 configuration management system (CMI). Learn why configuration management is one of the most eagerly anticipated features of Drupal 8, and how it has the potential to completely change the workflow we use for building sites with Drupal. By addressing a number of long-standing issues in Drupal, CMI helps to separate content from configuration, provides a simple user interface for transporting configuration changes between multiple instances of the same site, and gives developers a consistent way to store and retrieve configuration in their code that is guaranteed to work with the rest of management tools provided.
Here's what we'll cover in this presentation:
- What is configuration management, and what problems does it solve
- The CMI user interface, and changes for site-builders
- The CMI API, and changes for modules developers
- What you can start learning now to ensure you're ready to use CMI
After watching this presentation you should have a better understanding of the importance of the new configuration management system and be excited about the improved workflows and ability to follow current best practices that it introduces to Drupal.
Additional resources
- Configuration Management tutorial series (Drupalize.Me)
- Introduction to YAML video tutorial
- Drupal.org documentation: Configuration API in Drupal 8
- Drupal.org documentation: Managing configuration in Drupal 8
- Principles of Configuration Management - Part One article by Chapter 3
- Principles of Configuration Management - Part Two article by Chapter 3
- The Drupal 8 configuration schema cheat sheet
This tutorial provides an overview of the major shift in Drupal 8 to an object-oriented architecture and was created to help you understand which concepts and terminology you will need to learn in order to interact with modules at a code level.
Other tutorials in this series on "What's New in Drupal 8" will cover major changes in specific areas of Drupal 8 module development, such as entities and fields, configuration management, web services, and hooks. This tutorial will focus on object-oriented PHP architectural changes, concepts, and terminology you will need to know as a module developer.
Specifically, we will present:
- an overview of object-oriented PHP
- why it was introduced into Drupal 8
- how it differs from procedural programming
- major OO-PHP concepts you'll find in core
To learn object-oriented PHP, you should begin with our OOP topic page.
[# card #]
nid: 2926
title: OOP topic
[# endcard #]
Additional resources
- Object-oriented PHP topic page (drupalize.me)
- Why the big architectural changes in Drupal 8 article (buytaert.net)
- PHP Manual: Classes and Objects (php.net)
- Objected-oriented programming conventions (api.drupal.org)
- Services and Dependency Injection Container (api.drupal.org)
This video was part of a series of presentations produced in anticipation of Drupal 8's official release. For information about Drupal 8 module development based on official releases of Drupal 8, view tutorials in our Drupal 8 Module Development series.
[# card #]
nid: 2766
title: Drupal 8 Module Development Guide
[# endcard #]
One of the things that makes Drupal an attractive platform for developers to build their applications with is its extensibility. If you've ever used a contributed module, or written your own, you've taken advantage of this fact. Almost everything about the way that Drupal core works can be altered, extended or even replaced in order to allow developers total control. Historically that's always been done by implementing hooks. In Drupal 8 however, we've got some new tools to allow module developers to extend, alter, and enhance core's functionality.
In this presentation we'll take a high-level look at these new options, including:
- The role of hooks in Drupal 8
- The new plugin system for adding functionality
- Using routes to map HTTP requests to custom code
- Events and event listeners
- The service container and adding new services
- Using the Entity API for data storage
After watching this presentation you should have basic knowledge of the various ways in which Drupal 8 can be extended, and when to use each one. You'll also get information about what you can do now to start preparing for using these new tools.
Additional resources
API Documentation on api.drupal.org:
Articles and Video Tutorials:
- Module Development Essentials (KnpUniversity on Drupalize.Me)
- Dependency Injection and the Art of Services and Containers video tutorials
- Responding to Events in Drupal 8 article
- Unravelling the Drupal 8 Plugin System article
- An Introduction to YAML (Drupalize.Me)
DrupalCon:
- Altering, Extending, and Enhancing Drupal 8 — Joe Shindelar (eojthebrave) (DrupalCon New Orleans, May 2016)
Drupal's Change log:
This video was part of a series of presentations produced in anticipation of Drupal 8's official release. To learn about Drupal 8's new Entity API, take a look at our Entity API series.
[# card #]
nid: 2792
title: Entity API series
[# endcard #]
In this presentation we're going to take a high-level look at the new Drupal 8 Entity Field API. This is an improved version of the Entity API and Field API that was started in Drupal 7. Entities are the new recommended way of dealing with data in Drupal and as such, familiarizing yourself with the workings of the Entity API will be important when it comes time to store or retrieve data from your custom modules. It's a big change from what we're used to in Drupal—directly accessing the database via the database abstraction layer—but the Entity Field API also has some distinct advantages.
This presentation covers:
- Improvements to the Entity API
- Improvements to the Field API
- Handlers, Controllers, and ways to manipulate entities
- Discussion of new types of things we can build with these changes
- What you can do to start learning now
After watching this presentation you should be able to articulate the improvements made to the Entity Field API in Drupal 8 and start to understand how you might make use of it in your own code. We'll also cover some of the things you can start doing now in order to prepare yourself to use the Entity Field API in Drupal 8.
Additional resources
- Community documentation for Entities (drupal.org)
- Entity API (api.drupal.org)
- Drupal 8 Entity API DrupalCon Austin presentation (austin2014.drupal.org)
- Topic: Entities (Drupalize.Me)
Blocks have always been a part of Drupal and have always been a very limiting way of putting content on your site. Just to make it a usable system, contributed modules were almost always required. Drupal 8 has come a long way and has added much needed functionality to the core block system.
In this presentation we will cover what is new when it comes to the block system in Drupal 8 and the advantages that it offers.
What is different?
- Custom blocks, and blocks in general, can be used more than once
- A block title is now an on/off check box instead of having to use <none>
- A block can be placed in more than one region
- You can create "block types" much like content types
- The UI is easier to use with new blocks now in a sidebar instead of at the bottom
- This sidebar UI allows for dynamic filtering to make it even easier to find a block
- Configurations of block types and layout are now in code
- Blocks are plugins
To learn more about blocks, refer to our Blocks topic page.
[# card #]
nid: 2936
title: Blocks topic
[# endcard #]
Additional resources
Drupal 8 has done quite a few things to make things much easier for site builders to empower content creators. There are more tools in core that tremendously help content creators to quickly add and edit content. These tools are also mobile-friendly which makes content editing possible across more devices.
New features in core for content editors:
- Text formats and editor configuration
- CKEditor
- Drag and drop editor toolbar configuration
- Image captions
- Quick edit
- Better preview with view mode options
- Responsive and mobile-friendly interface
How do these changes help? To start; currently you need to add modules and outside editors just to get an editor in Drupal. The configuration of that editor is very cumbersome with lots of checkboxes and a very unfriendly UI. Besides a better user experience when it comes to configuring the authoring experience, adding and editing content on the go via mobile devices is a must have for today's modern CMS.
Additional resources
This video was part of a series of presentations produced in anticipation of Drupal 8's official release. For information about responsive design tools based on official releases of Drupal 8, view tutorials in our Responsive Web Design topic.
[# card #]
nid: 2968
title: Responsive Web Design topic
[# endcard #]
Drupal 8 is now a friend of mobile—mobile users, mobile developers, and even mobile site administrators. In this presentation, we'll look at the variety of mobile-friendly features added to Drupal 8 in the areas of site administration, site building, and module development.
"Mobile" means different things to different folks. For a content editor, being able to quickly update a piece of content from any device means one less barrier to getting a task done, when and where they want. For a developer, the prospect of diving into web services and building APIs that can be used for mobile apps or in conjunction with the latest Javascript framework is empowering and exciting, especially since the work of structuring entities and fields and administrating content can stay in Drupal. For the site builder, who simply wants to quickly get a site up and running out-of-the-box with a theme that "just works on mobile," the default responsive theme, Bartik, is a time-saver for sure.
By the end of this lesson, you'll have a better idea of the depth and breadth of what "mobile" means for Drupal 8 users of all kinds.
Additional resources
This course introduces important concepts in object-oriented PHP. It is authored and produced by our partners at KnpUniversity (now SymfonyCasts). In this PHP course, you'll be building a PHP app using PHP and refactoring the code, step-by-step, using concepts in OO-PHP such as classes, methods, access control, type hinting, and constructors. You'll learn how to have one object interact with another and by the end of this project, your PHP app will be sporting some shiny new object-oriented PHP.
In this lesson, Leanna introduces you to the project and shows you how to get it up and running. So, look for the Course code download link below and we'll walk you through the process of getting the app up and running on your computer using the built-in PHP server. As long as you have PHP installed on your computer and a code or text editor, you should be able to complete the lessons in this series. (A full stack web server (i.e. Apache/MySQL/PHP) is not required, only PHP.) Follow along by running commands from the start
directory.
Additional resources
This PHP tutorial covers the basics of classes and objects. You'll learn how to set up a class and then what a class is and what objects are like. By the end of this tutorial you should be able to create a class, an object, create a property, and set the value of a property inside a class.
Additional resources
In this PHP tutorial, you'll learn about methods — functions that live inside objects. You'll also learn how to access properties inside methods using the $this
pseudo-variable.
Additional resources
In this PHP tutorial, you'll get more practice working with methods. Along with adding some functionality to a method using PHP's sprintf()
function to format a string, you'll use the $this
pseudo-variable, and learn how to add and use arguments with methods.
Additional resources
In this PHP tutorial you'll learn how to work with multiple object instances of the same class that have different data and function independently.
Additional resources
In this PHP tutorial, you'll learn how to create a method that will enable multiple objects to interact with each other.
Additional resources
In this PHP tutorial, you'll learn how to add a specially-formatted comment to your method that will enable additional autocomplete functionality in IDEs such as PHPStorm.
Additional resources
In this PHP tutorial, you'll learn how to refactor the practice code in play.php into the Ship class. You'll get more practice working inside of a class and with objects.
Additional resources
In this PHP tutorial, you'll learn about to change the visibility of properties to private
and how this affects how these properties can be accessed. You'll change the public properties to private and then add "getter" and "setter" methods to the class to enable controlled access of the values of these private properties.
Note: the word "hooks" in this video does not refer to hooks in Drupal's API.
Note: PHP does provide magic methods for getting and setting which are explained in this tutorial: Magic Methods: __toString(), __get, __set.
Additional resources
In this PHP tutorial, you'll learn how Type Hinting can help you get better errors from PHP as you develop your application. You'll learn to debug errors and see how Type Hinting impacts the phrasing of the error messages you receive.
Additional resources
In this PHP tutorial, you'll learn how to use Constructors to set up objects and perform certain operations when a new object of this type is instantiated.
Additional resources
Constructors and Destructors (PHP Manual)
Explore more PHP tutorials