File size: 1,813 Bytes
d2897cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

declare(strict_types=1);

namespace Mautic\IntegrationsBundle\Event;

use Mautic\CoreBundle\Event\CommonEvent;

/**
 * This event is dispatched to allow plugins to provide tokens which create links
 * to any synced integration objects they may provide.
 */
class MappedIntegrationObjectTokenEvent extends CommonEvent
{
    private array $tokens = [];

    /**
     * Add a new mapped integration object token.
     *
     * @param string $integrationName - The name of the integration
     * @param        $objectName      - The name of the object in sync_object_mapping table
     * @param        $objectLink      - The base_url to direct users to the object on the integration site
     * @param string $title           - The title of the token in the token select dropdown
     * @param string $linkText        - The link text used for the url provided in $objectLink
     * @param string $default         - The default value to show when the token value isnt found
     */
    public function addToken(
        $integrationName,
        $objectName,
        $objectLink,
        $title = '',
        $linkText = 'Link Text',
        $default = 'Default Value'
    ): void {
        $this->tokens[$integrationName][$objectName] = [
            'base_url'    => $objectLink,
            'token_title' => $title,
            'link_text'   => $linkText,
            'default'     => $default,
        ];
    }

    /**
     * @return array
     */
    public function getTokens()
    {
        return $this->tokens;
    }

    /**
     * Get only the tokens provided by a particular integration.
     *
     * @param string $integrationName
     *
     * @return array
     */
    public function getTokensByIntegration($integrationName)
    {
        return $this->tokens[$integrationName] ?? [];
    }
}