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.
Custom KanbanService
Collapse
X
-
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" } }
-
No need to define a container service.
PHP Code:$binder->bindInstance(\Espo\Tools\Kanban\KanbanService::class, \Espo\Custom\Tools\Kanban\CustomKanbanService::class);
As an alternative, you can define a new route for the same URI path that will call a custom API action.If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.Comment
-
What error did you get? I just tried to define a custom route for an existing route path and it worked. -
ERROR: Slim Application Error Type: FastRoute\BadRouteException Code: 0 Message: Cannot register two routes matching "/api/v1/Kanban/([^/]+)" for method "GET" File: /var/www/espocrm/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php Line: 111
-
-
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 ?
ThanksLast edited by rabii; 01-02-2024, 01:20 PM.Rabii
Web DevComment
-
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.
-
Comment