2017-05-25 07:29:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\CMS\Forms;
|
|
|
|
|
2017-09-05 04:38:38 +02:00
|
|
|
use SilverStripe\Admin\LeftAndMainFormRequestHandler;
|
2017-05-25 07:29:32 +02:00
|
|
|
use SilverStripe\Admin\ModalController;
|
|
|
|
use SilverStripe\Core\Extension;
|
|
|
|
use SilverStripe\Forms\Form;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decorates ModalController with insert internal link
|
2024-01-18 22:00:46 +01:00
|
|
|
*
|
|
|
|
* @extends Extension<ModalController>
|
2017-05-25 07:29:32 +02:00
|
|
|
*/
|
|
|
|
class InternalLinkModalExtension extends Extension
|
|
|
|
{
|
2017-09-05 04:38:38 +02:00
|
|
|
private static $url_handlers = [
|
|
|
|
'editorAnchorLink/$ItemID' => 'editorAnchorLink', // Matches LeftAndMain::methodSchema args
|
|
|
|
];
|
|
|
|
|
2020-04-19 06:18:01 +02:00
|
|
|
private static $allowed_actions = [
|
2017-05-25 07:29:32 +02:00
|
|
|
'editorInternalLink',
|
2017-09-05 04:38:38 +02:00
|
|
|
'editorAnchorLink',
|
2020-04-19 06:18:01 +02:00
|
|
|
];
|
2017-05-25 07:29:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Form for inserting internal link pages
|
|
|
|
*
|
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
public function editorInternalLink()
|
|
|
|
{
|
2017-08-03 03:32:14 +02:00
|
|
|
$showLinkText = $this->getOwner()->getRequest()->getVar('requireLinkText');
|
2017-05-25 07:29:32 +02:00
|
|
|
$factory = InternalLinkFormFactory::singleton();
|
2017-08-03 03:32:14 +02:00
|
|
|
return $factory->getForm(
|
|
|
|
$this->getOwner(),
|
|
|
|
"editorInternalLink",
|
|
|
|
[ 'RequireLinkText' => isset($showLinkText) ]
|
|
|
|
);
|
2017-05-25 07:29:32 +02:00
|
|
|
}
|
2017-09-05 04:38:38 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2017-05-25 07:29:32 +02:00
|
|
|
}
|