-
Notifications
You must be signed in to change notification settings - Fork 96
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 Provide a way to register link forms dynamically for ModalController #1860
API Provide a way to register link forms dynamically for ModalController #1860
Conversation
protected function getSchemaResponse(string $schemaID, ?Form $form = null, ValidationResult $errors = null, array $extraData = []): HTTPResponse | ||
public function getSchemaResponse(string $schemaID, ?Form $form = null, ValidationResult $errors = null, array $extraData = []): HTTPResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be public to avoid code duplication. See silverstripe/silverstripe-asset-admin#1515
/** | ||
* Check if the current request has a X-Formschema-Request header set. | ||
* Used by conditional logic that responds to validation results | ||
*/ | ||
protected function getSchemaRequested(): bool | ||
{ | ||
$parts = $this->getRequest()->getHeader(static::SCHEMA_HEADER); | ||
return !empty($parts); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has just been moved further down the file so it's not above the public method
.replace(/:pageid/, ownProps.currentPageID); | ||
.replace(/:pageid/, ownProps.currentPageID || 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most link forms don't actually need the current page, so the JS plugins don't pass it through. In those cases 0
is sufficient.
Without this it'd be undefined
which gets included as a string in the URL which causes errors.
The alternative would be to update the other link plugins to include the actual ID but a) the way the anchor link plugin grabs it right now feels a little flakey and b) they don't need it so there's no need to add that functionality for them.
if ($modalName === null || $itemID === null) { | ||
$this->jsonError(400, 'Missing request params'); | ||
} | ||
$modalForms = static::config()->get('link_modal_form_factories'); | ||
if (!array_key_exists($modalName, $modalForms)) { | ||
$this->httpError(400); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 400
for consistency with the schema()
method on the superclass.
'linkModalForm/'.$modalName, | ||
[ | ||
'RequireLinkText' => isset($showLinkText), | ||
'ItemID' => $itemID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ItemID
is currently only used by the anchor link form, but a) adding it here allows us to include that form via the config instead of having a whole extension for it and b) this means future forms and custom project forms can use it if they want.
* Gets a JSON schema representing the current edit form. | ||
* Gets a JSON schema representing a form. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change but the form isn't necessarily (or even usually) the "current edit form" (implying main record edit form which isn't in a modal most of the time).
3ac554d
to
993740a
Compare
Reduces boilerplate required to set up an insert link modal form for the WYSIWYG
Issue
ModalController
#1765