summaryrefslogtreecommitdiff
path: root/doc/plugin-overrides.markdown
blob: 3b94bd605456e8a811729bbf42181ddd15913cf5 (plain)
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
64
65
66
67
68
69
70
71
72
73
Plugin Overrides
================

Override HTTP Content Security Policy
-------------------------------------

If you would like to replace the default HTTP Content Security Policy header, you can use the method `setContentSecurityPolicy()`:

```php
<?php

namespace Kanboard\Plugin\Csp;

use Kanboard\Core\Plugin\Base;

class Plugin extends Base
{
    public function initialize()
    {
        $this->setContentSecurityPolicy(array('script-src' => 'something'));
    }
}
```

Template Overrides
------------------

Any templates defined in the core can be overridden. For example, you can redefine the default layout or change email notifications.

Example of template override:

```php
$this->template->setTemplateOverride('header', 'theme:layout/header');
```

The first argument is the original template name and the second argument the template to use as replacement.

You can still use the original template using the "kanboard:" prefix:

```php
<?= $this->render('kanboard:header') ?>
```

Formatter Overrides
-------------------

Here an example to override formatter objects in Kanboard:

```php
class MyFormatter extends UserAutoCompleteFormatter
{
    public function format()
    {
        $users = parent::format();

        foreach ($users as &$user) {
            $user['label'] = 'something'; // Do something useful here
        }

        return $users;
    }
}

class Plugin extends Base
{
    public function initialize()
    {
        $this->container['userAutoCompleteFormatter'] = $this->container->factory(function ($c) {
            return new MyFormatter($c);
        });
    }
}
```