Drupal 8 is a Great Way of Developing an Useful and Valuable Website - Part Twelve

feature-top

Alright on the last article we promised that we were going to talk more about services, so this is what we are going to do here. Let’s delve right to it, another property of services is the configurator property, which is used to configure a service after it has been installed, where there is a service, which requires a complex setup. The configuration of the configurator property would usually come from a different source or service.

Another property of the service file is the factory property, which is where the service class is instantiated through a class. The file property is a file included just before the service, and the tags property is used to identify groups of services. There are other properties defined at drupal.org, I don’t want to focus too much on the property although they are very important.

Let’s continue to talk about the structure of the service files and directory. Now that we are aware of the different properties found in the service .yml file, let’s look at the other components needed to use a service. There is one more property, which is important to note, is known as the class property, which is used to point to any .php file found in the src/Services directory. The .php file will allow you to call your dependencies and use them however you need.

<?php

   Class WatchCartoons {

     …………

      Public function __construct(ConfigFactory $cofig_factory) {

        $this->config_factory = $config_factory

      }

     …………

   }

<?php

 

 

 

class WatchCartoons {

 

...

 

public function __construct(ConfigFactory $config_factory) {

 

$this->config_factory = $config_factory;

 

}

 

...

 

}

 

The above code is an example of a .php file which is making a call to a dependency using the constructor method in the __construct() constructor for the class. In the above code, you’ll see that we named a class called WatchCartoon, which has a method that injects a service called ConfigFactory.

The code does not do anything, because it is not complete, but you can find more information at FFW. This is as far as I can take you with services, go and create your own, there is so much information about them and you can find it online for free so that you can also start to create and use services on your Drupal 8 site.

Splitting functionalities into reusable components is the idea behind a service, which can be used to accomplish many things in Drupal 8. It would be a good practice for you as a developer to create your own service or use an existing one. Creating your own service will allow you to become a master at what you just read, but if you are still unsure about this daunting task you can go on ahead and read more on the subject.

I wouldn’t suggest you start doing something in Drupal 8 if you haven’t done your research first. If you do that, then you will run into a wall, because there are things you won’t be aware off at first, when you develop your application using Drupal 8.

Thank you for reading this article!!!

 

feature-top
feature-top

Add a Comment

Hernando Cadet

Hi every one, I obtained a bachelor's degree in Bioinformatics back in 2006, from Claflin University, after I received my bachelor's degree, I gained full time employment as a software engineer at a Video Relay Service company, maintaining databases and developing software for a new developed device called the VPAD.

I worked at that company for two years, then I became a web developer, and worked for a magazine for three years. After that job, I worked as a Drupal web developer, as a subcontractor for the NIH, for a year and then left the job to go back to school.

Hernando Cadet

Collaboratively administrate empowered markets via plug-and-play networks. Dynamically procrastinate B2C users after installed base benefits. Dramatically visualize customer directed convergence without

Collaboratively administrate empowered markets via plug-and-play networks. Dynamically procrastinate B2C users after installed base benefits. Dramatically visualize customer directed convergence without revolutionary ROI.