Passed
Push — master ( f3d1e6...12f788 )
by Robbie
03:58 queued 01:57
created

MakeShareDraftLink()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 4
nop 0
dl 0
loc 11
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\ShareDraftContent\Extensions;
4
5
use SilverStripe\Core\Extension;
6
use SilverStripe\Security\Security;
7
8
class ShareDraftContentControllerExtension extends Extension
9
{
10
    /**
11
     * @var array
12
     */
13
    private static $allowed_actions = array(
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
14
        'MakeShareDraftLink',
15
    );
16
17
    /**
18
     * @return mixed
19
     */
20
    public function MakeShareDraftLink()
21
    {
22
        if ($member = Security::getCurrentUser()) {
23
            if ($this->owner->hasMethod('CurrentPage') && $this->owner->CurrentPage()->canEdit($member)) {
24
                return $this->owner->CurrentPage()->ShareTokenLink();
25
            } elseif ($this->owner->hasMethod('canEdit') && $this->owner->canEdit($member)) {
26
                return $this->owner->ShareTokenLink();
27
            }
28
        }
29
30
        return Security::permissionFailure();
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public function getShareDraftLinkAction()
37
    {
38
        if ($this->owner->config()->get('url_segment')) {
39
            return $this->owner->Link('MakeShareDraftLink');
40
        }
41
        return '';
42
    }
43
}
44