Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Use dynamic config for ModalController forms #3029

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ SilverStripe\Admin\LeftAndMain:
Name: cmsmodals
---
SilverStripe\Admin\ModalController:
extensions:
- SilverStripe\CMS\Forms\InternalLinkModalExtension
link_modal_form_factories:
editorInternalLink: SilverStripe\CMS\Forms\InternalLinkFormFactory
editorAnchorLink: SilverStripe\CMS\Forms\AnchorLinkFormFactory
---
Name: cmshierarchy
---
SilverStripe\ORM\Hierarchy\Hierarchy:
node_threshold_total: 50
node_threshold_leaf: 250
node_threshold_leaf: 250
2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_sslink-anchor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_sslink-internal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/src/legacy/TinyMCE_sslink-anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const plugin = {
};

const modalId = 'insert-link__dialog-wrapper--anchor';
const sectionConfigKey = 'SilverStripe\\CMS\\Controllers\\CMSPageEditController';
const sectionConfigKey = 'SilverStripe\\Admin\\LeftAndMain';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LeftAndMain now dynamically lists all link forms registered with ModalController.link_modal_form_factories

These do get inherited, so CMSPageEditController would still work, but it seems sensible to use the more generic controller here (especially since CMSPageEditController is not long for this world)

const formName = 'editorAnchorLink';
const InsertLinkInternalModal = provideInjector(createInsertLinkModal(sectionConfigKey, formName));

Expand Down
2 changes: 1 addition & 1 deletion client/src/legacy/TinyMCE_sslink-internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const plugin = {
};

const modalId = 'insert-link__dialog-wrapper--internal';
const sectionConfigKey = 'SilverStripe\\CMS\\Controllers\\CMSPageEditController';
const sectionConfigKey = 'SilverStripe\\Admin\\LeftAndMain';
const formName = 'editorInternalLink';
const InsertLinkInternalModal = provideInjector(createInsertLinkModal(sectionConfigKey, formName));

Expand Down
8 changes: 0 additions & 8 deletions code/Controllers/CMSPageEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Page;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Admin\ModalController;
use SilverStripe\CampaignAdmin\AddToCampaignHandler;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
Expand Down Expand Up @@ -37,18 +36,11 @@ class CMSPageEditController extends CMSMain

public function getClientConfig(): array
{
$modalController = ModalController::singleton();
return ArrayLib::array_merge_recursive(parent::getClientConfig(), [
'form' => [
'AddToCampaignForm' => [
'schemaUrl' => $this->Link('schema/AddToCampaignForm'),
],
'editorInternalLink' => [
'schemaUrl' => $modalController->Link('schema/editorInternalLink'),
],
'editorAnchorLink' => [
'schemaUrl' => $modalController->Link('schema/editorAnchorLink/:pageid'),
],
Comment on lines -46 to -51
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These get included in LeftAndMain::getClientConfig() now instead.

],
]);
}
Expand Down
4 changes: 2 additions & 2 deletions code/Forms/AnchorLinkFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected function getFormFields($controller, $name, $context)

// Ensure current page is selected
$pageIDField = $fields->dataFieldByName('PageID');
$pageIDField->setValue((int)$context['PageID']);
$pageIDField->setValue((int)$context['ItemID']);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed to be more generic so we can reuse it in other link forms if needed.


// Get anchor selector field
$fields->insertAfter(
Expand All @@ -22,6 +22,6 @@ protected function getFormFields($controller, $name, $context)

public function getRequiredContext()
{
return array_merge(parent::getRequiredContext(), [ 'PageID' ]);
return array_merge(parent::getRequiredContext(), [ 'ItemID' ]);
}
}
73 changes: 0 additions & 73 deletions code/Forms/InternalLinkModalExtension.php

This file was deleted.

Loading
Loading