-
Notifications
You must be signed in to change notification settings - Fork 331
/
InternalLinkModalExtension.php
62 lines (54 loc) · 1.73 KB
/
InternalLinkModalExtension.php
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
<?php
namespace SilverStripe\CMS\Forms;
use SilverStripe\Admin\LeftAndMainFormRequestHandler;
use SilverStripe\Admin\ModalController;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\Form;
/**
* Decorates ModalController with insert internal link
*
* @extends Extension<ModalController>
*/
class InternalLinkModalExtension extends Extension
{
private static $url_handlers = [
'editorAnchorLink/$ItemID' => 'editorAnchorLink', // Matches LeftAndMain::methodSchema args
];
private static $allowed_actions = [
'editorInternalLink',
'editorAnchorLink',
];
/**
* Form for inserting internal link pages
*
* @return Form
*/
public function editorInternalLink()
{
$showLinkText = $this->getOwner()->getRequest()->getVar('requireLinkText');
$factory = InternalLinkFormFactory::singleton();
return $factory->getForm(
$this->getOwner(),
"editorInternalLink",
[ 'RequireLinkText' => isset($showLinkText) ]
);
}
public function editorAnchorLink()
{
// Note: Should work both via MethodSchema and as direct request
$request = $this->getOwner()->getRequest();
$showLinkText = $request->getVar('requireLinkText');
$pageID = $request->param('ItemID');
$factory = AnchorLinkFormFactory::singleton();
$form = $factory->getForm(
$this->getOwner(),
"editorAnchorLink",
[ 'RequireLinkText' => isset($showLinkText), 'PageID' => $pageID ]
);
// Set url handler that includes pageID
$form->setRequestHandler(
LeftAndMainFormRequestHandler::create($form, [$pageID])
);
return $form;
}
}