Announcement

Collapse
No announcement yet.

Custom KanbanService

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom KanbanService

    Is it possible to create custom KanbanService to be used instead of standard one? I tried to create new class in custom/Espo/Custom/Tools dir, but it has no affect.

  • #2
    Take a look at Dependency Injection. I haven't tested it, but you could give this a try to see if it works. Make sure the namespaces are correct.

    Code:
    custom/Espo/Custom/Binding.php
    PHP Code:
    <?php
    namespace Espo\Custom;

    use 
    Espo\Core\Binding\Binder;
    use 
    Espo\Core\Binding\BindingProcessor;

    class 
    Binding implements BindingProcessor
    {
        public function 
    process(Binder $binder): void
        
    {
            
    $binder
                
    ->bindService('Espo\\Tools\\Kanban\\KanbanService $service''customKanbanService');
        }
    }
    Code:
    custom/Espo/Custom/Resources/metadata/app/containerServices.json
    Code:
    {
        "customKanbanService": {
            "className": "Espo\\Custom\\Tools\\Kanban\\KanbanService"
        }
    }
    ​

    Comment


    • #3
      No need to define a container service.

      PHP Code:
      $binder->bindInstance(\Espo\Tools\Kanban\KanbanService::class, \Espo\Custom\Tools\Kanban\CustomKanbanService::class);​ 
      CustomKanbanService should extend KanbanService, as there's no interface.

      As an alternative, you can define a new route for the same URI path that will call a custom API action.

      Comment


      • yuri
        yuri commented
        Editing a comment
        What error did you get? I just tried to define a custom route for an existing route path and it worked.

      • a.slyzhko
        a.slyzhko commented
        Editing a comment
        ERROR: Slim Application Error Type: FastRoute\BadRouteException Code: 0 Message: Cannot register two routes matching &quot;/api/v1/Kanban/([^/]+)&quot; for method &quot;GET&quot; File: /var/www/espocrm/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php Line: 111

      • yuri
        yuri commented
        Editing a comment
        I see. I'll try to address this problem in v8.2.

    • #4
      Hey yuri

      What if we need to change a method on an existing class, e.g i want to change the method generate on this class Espo\Tools\Pdf\Service with my custom implementation in a custom service class Espo\Custom\Tools\Pdf\CustomService. would the binding class below work:

      PHP Code:
      <?php
      namespace Espo\Custom;

      use 
      Espo\Core\Binding\Binder;
      use 
      Espo\Core\Binding\BindingProcessor;

      class 
      Binding implements BindingProcessor
      {
          public function 
      process(Binder $binder): void
          
      {
             
      $binder
                 
      ->bindInstance(\Espo\Tools\Pdf\Service::class, \Espo\Custom\Tools\Pdf\CustomService::class);
          
      }
      }

      Do i still have to extend the pdf Service on my custom Services and implement a generate function to overwrite the function on the pdf service class ?

      Thanks
      Last edited by rabii; 01-02-2024, 01:20 PM.

      Comment


      • rabii
        rabii commented
        Editing a comment
        Hey Yuri,

        when i tried this $binder->bindInstance(\Espo\Tools\Pdf\Service::class, \Espo\Custom\Tools\Pdf\CustomService::class);

        It doesn't work. i get an error expected type object. when i checked the bindInstance it require an object as a second argument. Is there something i am missing. I am trying to bind the pdf service class with a custom pdf service class.

      • a.slyzhko
        a.slyzhko commented
        Editing a comment
        You need to instantiate your custom service and pass it as a second param, instead of using its name. ::class returns a string representing a name of the class, not an object of this class

      • rabii
        rabii commented
        Editing a comment
        i have tried that it didn't work either. But i figure it out instead of bindingInstance i have used an implemtation extending original class to my custom class and now it works like a charm.
    Working...
    X