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 Provide a way to register link forms dynamically for ModalController #1860

Merged

Conversation

GuySartorelli
Copy link
Member

Reduces boilerplate required to set up an insert link modal form for the WYSIWYG

Issue

Comment on lines -124 to +114
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
Copy link
Member Author

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

Comment on lines -106 to -114
/**
* 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);
}
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 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);
Copy link
Member Author

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.

Comment on lines +51 to +57
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);
}
Copy link
Member Author

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,
Copy link
Member Author

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.
Copy link
Member Author

@GuySartorelli GuySartorelli Nov 25, 2024

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).

@GuySartorelli GuySartorelli force-pushed the pulls/3/modal-controller branch from 3ac554d to 993740a Compare November 27, 2024 00:15
@GuySartorelli GuySartorelli marked this pull request as ready for review November 27, 2024 00:23
@emteknetnz emteknetnz merged commit 6859088 into silverstripe:3 Nov 27, 2024
13 checks passed
@emteknetnz emteknetnz deleted the pulls/3/modal-controller branch November 27, 2024 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants