![]() ![]() The set-top-box is a Service Container that gives you a means of accessing any of these Services, obscuring the technical details. If I'd rather watch HBO Go, I can ask my set-top-box to load that Service instead. I don't need to know the IP address and the API schema for Netflix in order to watch a film. Whether it's made by Apple, Amazon, Google or Roku, these set-top boxes all have Services in common. One way of thinking about Services, if this is a new concept for you, is the set-top-box on your TV. This way, you don't have to know where the link_generator class is defined, or even what class name it uses, but you can always find it if you need to. This says to get the service called link_generator and call its generate() method. You call the function as such \Drupal::l(), because everything is namespaced now, but that's another blog post. Many of the core systems are implemented as services, and many familiar core functions are now procedural wrappers for services.įor example, the l() function is now a wrapper for the LinkGenerator::generate() function. Services are used in a number of ways in Drupal. First, I'll show you how a common function, making links, uses services. The new Configuration Management systems in Drupal 8 use services extensively, and you will learn a bit about Config in this blog post. There is, however, a token service, which is a great example, since you only really need one token service for your entire site. For example, a node is not a service it is content. A View is also not a service. While Services are objects, not all objects are suitable services. For example, Drupal 8 sites have a service for sending email, for logging errors, for making HTTP requests, and dozens of other common tasks. ![]() Chief among them was the concept in Symfony and Drupal 8 called Services, which help keep your code decoupled and, in my opinion, easier to read.Ī Service is simply an object, usually with one instance of each service's class for each service on a site. IntroĪs a dyed-in-the-wool Drupal programmer looking to get into coding Drupal 8, there were a few modern subjects I had to familiarize myself with.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |