Step 1: Define the Service
You can now use your custom service as a helper wherever needed in your Drupal codebase, below is an example used in the confirm form CustomConfirmForm.php
.
Step 2: Create the Service Class
Create a new custom module or use an existing one. Define your service in the module’s directory custom_module.services.yml
file, below shown the sample.
Step 3: Use the Service as a Helper
Create a new Php class CustomServiceHelper.php
, that implements the service’s functionality Thanks for reading the article, for more drupal related articles read and subscribe to peoples blog articles. In this article we are sharing an example of how to create a custom Drupal service and use it as a helper.