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
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
This video was part of a series of presentations produced in anticipation of Drupal 8's official release. For information about multilingual sites based on official releases of Drupal 8, take a look at our Multilingual sites topic.
[# card #]
nid: 2925
title: Multilingual sites topic
[# endcard #]
This presentation outlines some of the major changes to the Drupal core multilingual system. A lot of features that were in contributed modules have been rolled into core, and a number of existing multilingual features have been greatly improved. There are a lot of cool new things to get up to speed with. In this video, we'll review:
- New and obsolete modules
- UI changes
- Developer changes
After watching this presentation you should have a better understanding of the things you'll need to learn to get up to speed with the new multilingual features in Drupal 8, including things to watch for on the module development and theming sides.
Additional resources
Drupal 8 Multilingual Initiative site
Gábor Hojtsy's Multilingual Changes Summary (PDF)
This presentation walks through quite a long list of major contributed modules and best practices that have been incorporated into Drupal 8 core. There are a lot of new features that you'll get out of the box, from Views to Services. In particular we'll cover:
- Exactly what best practices mean
- How core and contributed modules help the community define best practices
- List the major categories of features that have been incorporated
After watching this presentation you should have a better understanding of what best practices are, and a list of the major contributed modules from Drupal 7 that have been added, in one form or another, into Drupal 8.
In this PHP tutorial we are going to continue to remove the flat functions in our code. We'll refactor one of them to a private function and create a new ShipLoader
service class to clean up the rest. With this refactoring in place, we'll be able to rename the functions.php file since it won't contain any functions any longer.