-
Notifications
You must be signed in to change notification settings - Fork 94
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
NEW Move form schema logic into FormSchemaController #1850
base: 3
Are you sure you want to change the base?
NEW Move form schema logic into FormSchemaController #1850
Conversation
if (!$this->schema) { | ||
$this->schema = FormSchema::singleton(); | ||
} |
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 wasn't there in LeftAndMain
but it's a little protection in case the dependency doesn't get injected (e.g. not using injector to instantiate this controller for some reason)
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.
The code in this class is mostly directly copied in from LeftAndMain
.
Note that there were no existing unit tests explicitly for the methods in this class - instead, this functionality is fairly heavily tested in behat (linkfield, elemental, history controller, WYSIWYG link modals all use it)
26138b8
to
0fb29a4
Compare
code/FormSchemaController.php
Outdated
// The getter can accept an ID where the main form action wouldn't | ||
$formMethod = "get{$formName}"; | ||
if (!$this->hasMethod($formMethod)) { | ||
$formMethod = $formName; | ||
if (!$this->hasMethod($formMethod)) { | ||
$this->jsonError(404, 'Form not found'); | ||
} | ||
} |
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 usages of this method right now (e.g. see AssetAdmin) have two methods - one method is named the same as the form, and does not accept a parameter - the other prefixed with get
and accepts a parameter.
The usages of ModalController
used to go through methodSchema
on LeftAndMain
- but now we just go directly through schema
on ModalController
. Those methods do not have get
prefixes.
I'm not going through and refactoring all of those - that's out of scope. Instead, I've just updated this method to account for both scenarios.
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.
Could you put some the github comment info into the inline comment - by itself the existing comment "The getter can accept an ID where the main form action wouldn't" is pretty confusing
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.
Happy to do so, but I'm not sure what you find confusing about it so I don't know what info you want in there. What would you like the comment to say? Or what about the existing comment is confusing?
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 usages of this method (e.g. AssetAdmin) have two methods - one method is named the same as the form, and does not accept a parameter - the other prefixed with "get" and accepts an $itemID
parameter.
^ Maybe just the comment to this
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.
Done
0fb29a4
to
e1e8534
Compare
* Get the form schema from a given method. | ||
* The method must return a Form. | ||
*/ | ||
public function methodSchema(HTTPRequest $request): 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.
This method was just a bizarre way to avoid directly linking to ModalController
.
It's not used anywhere now that we're linking to ModalController
directly. If anyone's using it directly in their own projects or modules, the recommendation will be to directly link to the schema
for the FormSchemaController
that handles that form, instead of this indirection.
e1e8534
to
daba832
Compare
code/FormSchemaController.php
Outdated
protected function init() | ||
{ | ||
$this->beforeExtending('onInit', function () { | ||
// Set the members html editor config | ||
if (Security::getCurrentUser()) { | ||
HTMLEditorConfig::set_active_identifier(Security::getCurrentUser()->getHtmlEditorConfigForCMS()); | ||
} | ||
|
||
// Set default values in the config if missing. These things can't be defined in the config | ||
// file because insufficient information exists when that is being processed | ||
$htmlEditorConfig = HTMLEditorConfig::get_active(); | ||
$htmlEditorConfig->setOption('language', TinyMCEConfig::get_tinymce_lang()); | ||
$langUrl = TinyMCEConfig::get_tinymce_lang_url(); | ||
if ($langUrl) { | ||
$htmlEditorConfig->setOption('language_url', $langUrl); | ||
} | ||
}); | ||
parent::init(); | ||
} |
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.
Needed for controllers such as ElementalAreaController
which may include WYSIWYG in their forms.
daba832
to
19b9eda
Compare
@@ -104,7 +94,6 @@ class LeftAndMain extends AdminController implements PermissionProvider | |||
* | |||
* @config | |||
* @var string | |||
* @deprecated 2.4.0 Will be renamed to model_class |
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 - was missed in a merge-up
code/FormSchemaController.php
Outdated
{ | ||
$this->beforeExtending('onInit', function () { | ||
// Set the members html editor config | ||
if (Security::getCurrentUser()) { |
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.
Looks kind of messy having all of this here around the top of the file since it's all TinyMCE related which is weird in a FormSchema class. Move it to a private method down the bottom of the class
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.
TinyMCE is in forms, so form schema having form stuff doesn't seem weird to me. Done anyway though.
code/FormSchemaController.php
Outdated
} | ||
|
||
/** | ||
* Get form schema helper |
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.
* Get form schema helper | |
* Get the form schema helper for this controller |
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.
Done
code/FormSchemaController.php
Outdated
} | ||
|
||
/** | ||
* Set form schema helper for this controller |
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.
* Set form schema helper for this controller | |
* Set the form schema helper for this controller |
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.
Done
} | ||
|
||
if (!$this->hasAction($formName)) { | ||
$this->jsonError(401, 'Form not accessible'); |
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->jsonError(401, 'Form not accessible'); | |
$this->jsonError(404, 'Form not accessible'); |
It's an invalid route, rather than an issue with a user not being logged in
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.
Changing error codes is not in scope for this PR. This isn't new code.
code/FormSchemaController.php
Outdated
// The getter can accept an ID where the main form action wouldn't | ||
$formMethod = "get{$formName}"; | ||
if (!$this->hasMethod($formMethod)) { | ||
$formMethod = $formName; | ||
if (!$this->hasMethod($formMethod)) { | ||
$this->jsonError(404, 'Form not found'); | ||
} | ||
} |
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.
Could you put some the github comment info into the inline comment - by itself the existing comment "The getter can accept an ID where the main form action wouldn't" is pretty confusing
19b9eda
to
c0a917e
Compare
c0a917e
to
4d72be8
Compare
In a perfect world
LeftAndMain
would not be a subclass of the newFormSchemaController
class - but so many of its subclasses rely directly on that logic, and refactoring those to spin off sub-controllers looks like way more work than it's really worth.I thought of making the new class a trait instead, but if a trait has
private static
properties the subclass can't also have those private static properties.We could implement
getExtraMethodConfig()
in the trait to work around that, but that's an ugly solution imo.This PR still takes us closer to making
LeftAndMain
abstract (since it doesn't need to routeModals
anymore) and makes it easier to have non-LeftAndMain
form schema controllers, and those are the main goals for this card.Issue
LeftAndMain
into its own abstract class #1762