Passed
Push — 1.11.x ( 080d0e...e78a37 )
by Angel Fernando Quiroz
10:16
created

FrmEdit::setDefaultValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 9.9666
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
use Chamilo\PluginBundle\Entity\LtiProvider\Platform;
5
6
/**
7
 * Class FrmAdd.
8
 */
9
class FrmEdit extends FormValidator
10
{
11
    /**
12
     * @var Platform|null
13
     */
14
    private $platform;
15
16
    /**
17
     * FrmAdd constructor.
18
     */
19
    public function __construct(
20
        string $name,
21
        array $attributes = [],
22
        Platform $platform = null
23
    ) {
24
        parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL);
25
26
        $this->platform = $platform;
27
    }
28
29
    /**
30
     * Build the form.
31
     *
32
     * @throws Exception
33
     */
34
    public function build(bool $globalMode = true)
35
    {
36
        $plugin = LtiProviderPlugin::create();
37
        $this->addHeader($plugin->get_lang('ConnectionDetails'));
38
39
        $this->addText('issuer', $plugin->get_lang('PlatformName'));
40
        $this->addUrl('auth_login_url', $plugin->get_lang('AuthLoginUrl'));
41
        $this->addUrl('auth_token_url', $plugin->get_lang('AuthTokenUrl'));
42
        $this->addUrl('key_set_url', $plugin->get_lang('KeySetUrl'));
43
        $this->addText('client_id', $plugin->get_lang('ClientId'));
44
        $this->addText('deployment_id', $plugin->get_lang('DeploymentId'));
45
        $this->addText('kid', $plugin->get_lang('KeyId'));
46
47
        $this->addButtonCreate($plugin->get_lang('EditPlatform'));
48
        $this->addHidden('id', $this->platform->getId());
49
        $this->addHidden('action', 'edit');
50
        $this->applyFilter('__ALL__', 'trim');
51
    }
52
53
    /**
54
     * @throws Exception
55
     */
56
    public function setDefaultValues(): void
57
    {
58
        $defaults = [];
59
        $defaults['issuer'] = $this->platform->getIssuer();
60
        $defaults['auth_login_url'] = $this->platform->getAuthLoginUrl();
61
        $defaults['auth_token_url'] = $this->platform->getAuthTokenUrl();
62
        $defaults['key_set_url'] = $this->platform->getKeySetUrl();
63
        $defaults['client_id'] = $this->platform->getClientId();
64
        $defaults['deployment_id'] = $this->platform->getDeploymentId();
65
        $defaults['kid'] = $this->platform->getKid();
66
67
        $this->setDefaults($defaults);
68
    }
69
}
70