Mautic Community Forums

Custom Integration service not able to get keys from saved encrypted settings

Hi Mautic Community Folks,

I have been facing a stupid issue, I have developed integration plugin to connect to third party application but the issue is that when I inject this service in my controller or event listener, I am not really getting to use it completely.

Let’s go step by step so I am able to describe my problem better:

here’s how my config looks:
‘services’ => [
‘events’ => [
‘mautic.integration.appname.form.subscriber’ => [
‘class’ => \MauticPlugin\MauticAppnameBundle\EventListener\OnboardingFormSubscriber::class,
‘arguments’ => [
‘monolog.logger’,
‘session’,
‘doctrine.orm.default_entity_manager’
‘mautic.integration.appname’
]
]
],
‘integrations’ => [
‘mautic.integration.appname’ => [
‘class’ => \MauticPlugin\MauticAppnameBundle\Integration\AppnameIntegration::class,
‘arguments’ =>
]
],
]

My Purpose: Once user is authenticated I need to push some data on specific event, for which I wrote the EventListeners and when in event listener I do:
$this->appnameService->getKeys();

I receive nothing, while I have found a workaround for now but it doesn’t seems right to go like this, I have taken references from multiple plugins like SocialBundle and CrmBundle as well as referred to the documentation exactly it doesn’t seems fit.

For the workaround I dig in the core bundles and found out this:
/** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper /
$integrationHelper = $this->get(‘mautic.helper.integration’);
/
* @var AbstractIntegration $integrationObject */
return $integrationHelper->getIntegrationObject(’’);

This works fine at some level for example in controller but in the injected service or form event it gives me issues becuase then I am injecting the container object in the Subscriber as well.

Can somebody point me in the right direction please ?

Regards,
Mayank

Edit:

here is an example of when used service obtained from container vs when used the object obtained from integration helper.