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

ShareDraftContentControllerExtension   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getShareDraftLinkAction() 0 6 2
A MakeShareDraftLink() 0 11 6
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