silverstripe-cms/code/Forms/InternalLinkModalExtension.php

73 lines
1.9 KiB
PHP
Raw Normal View History

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
* @see ModalController
*/
class InternalLinkModalExtension extends Extension
{
2017-09-05 04:38:38 +02:00
private static $url_handlers = [
'editorAnchorLink/$ItemID' => 'editorAnchorLink', // Matches LeftAndMain::methodSchema args
];
private static $allowed_actions = [
2017-05-25 07:29:32 +02:00
'editorInternalLink',
2017-09-05 04:38:38 +02:00
'editorAnchorLink',
];
2017-05-25 07:29:32 +02:00
/**
* @return ModalController
*/
public function getOwner()
{
/** @var ModalController $owner */
$owner = $this->owner;
return $owner;
}
/**
* Form for inserting internal link pages
*
* @return Form
*/
public function editorInternalLink()
{
$showLinkText = $this->getOwner()->getRequest()->getVar('requireLinkText');
2017-05-25 07:29:32 +02:00
$factory = InternalLinkFormFactory::singleton();
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
}