Completed
Push — master ( 780648...a93e4f )
by Daniel
06:19
created

InternalLinkModalExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 59
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getOwner() 0 6 1
A editorInternalLink() 0 10 1
A editorAnchorLink() 0 20 1
1
<?php
2
3
namespace SilverStripe\CMS\Forms;
4
5
use SilverStripe\Admin\LeftAndMainFormRequestHandler;
6
use SilverStripe\Admin\ModalController;
7
use SilverStripe\Core\Extension;
8
use SilverStripe\Forms\Form;
9
10
/**
11
 * Decorates ModalController with insert internal link
12
 * @see ModalController
13
 */
14
class InternalLinkModalExtension extends Extension
15
{
16
    private static $url_handlers = [
17
        'editorAnchorLink/$ItemID' => 'editorAnchorLink', // Matches LeftAndMain::methodSchema args
18
    ];
19
20
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
21
        'editorInternalLink',
22
        'editorAnchorLink',
23
    );
24
25
    /**
26
     * @return ModalController
27
     */
28
    public function getOwner()
29
    {
30
        /** @var ModalController $owner */
31
        $owner = $this->owner;
32
        return $owner;
33
    }
34
35
36
    /**
37
     * Form for inserting internal link pages
38
     *
39
     * @return Form
40
     */
41
    public function editorInternalLink()
42
    {
43
        $showLinkText = $this->getOwner()->getRequest()->getVar('requireLinkText');
44
        $factory = InternalLinkFormFactory::singleton();
45
        return $factory->getForm(
46
            $this->getOwner(),
47
            "editorInternalLink",
48
            [ 'RequireLinkText' => isset($showLinkText) ]
49
        );
50
    }
51
52
    public function editorAnchorLink()
53
    {
54
        // Note: Should work both via MethodSchema and as direct request
55
        $request = $this->getOwner()->getRequest();
56
        $showLinkText = $request->getVar('requireLinkText');
57
        $pageID = $request->param('ItemID');
58
        $factory = AnchorLinkFormFactory::singleton();
59
        $form = $factory->getForm(
60
            $this->getOwner(),
61
            "editorAnchorLink",
62
            [ 'RequireLinkText' => isset($showLinkText), 'PageID' => $pageID ]
63
        );
64
65
        // Set url handler that includes pageID
66
        $form->setRequestHandler(
67
            LeftAndMainFormRequestHandler::create($form, [$pageID])
68
        );
69
70
        return $form;
71
    }
72
}
73