Issues (3627)

Event/MappedIntegrationObjectTokenEvent.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * @copyright   2019 Mautic, Inc. All rights reserved
7
 * @author      Mautic, Inc.
8
 *
9
 * @link        https://mautic.com
10
 *
11
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Mautic\IntegrationsBundle\Event;
15
16
use Mautic\CoreBundle\Event\CommonEvent;
17
18
/**
19
 * This event is dispatched to allow plugins to provide tokens which create links
20
 * to any synced integration objects they may provide.
21
 *
22
 * Class MappedIntegrationObjectTokenEvent
23
 */
24
class MappedIntegrationObjectTokenEvent extends CommonEvent
25
{
26
    /**
27
     * @var array
28
     */
29
    private $tokens = [];
30
31
    /**
32
     * Add a new mapped integration object token.
33
     *
34
     * @param string $integrationName - The name of the integration
35
     * @param $objectName - The name of the object in sync_object_mapping table
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
36
     * @param $objectLink - The base_url to direct users to the object on the integration site
37
     * @param string $title    - The title of the token in the token select dropdown
38
     * @param string $linkText - The link text used for the url provided in $objectLink
39
     * @param string $default  - The default value to show when the token value isnt found
40
     */
41
    public function addToken(
42
        $integrationName,
43
        $objectName,
44
        $objectLink,
45
        $title = '',
46
        $linkText = 'Link Text',
47
        $default = 'Default Value'
48
    ): void {
49
        $this->tokens[$integrationName][$objectName] = [
50
            'base_url'    => $objectLink,
51
            'token_title' => $title,
52
            'link_text'   => $linkText,
53
            'default'     => $default,
54
        ];
55
    }
56
57
    /**
58
     * @return array
59
     */
60
    public function getTokens()
61
    {
62
        return $this->tokens;
63
    }
64
65
    /**
66
     * Get only the tokens provided by a particular integration.
67
     *
68
     * @param string $integrationName
69
     *
70
     * @return array
71
     */
72
    public function getTokensByIntegration($integrationName)
73
    {
74
        return $this->tokens[$integrationName] ?? [];
75
    }
76
}
77