-
Notifications
You must be signed in to change notification settings - Fork 815
Various changes to support refactoring CMS search filter functionality #11587
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -308,7 +308,9 @@ public function __construct( | |
| } | ||
|
|
||
| // Form error controls | ||
| $this->restoreFormState(); | ||
| if ($controller) { | ||
| $this->restoreFormState(); | ||
| } | ||
|
|
||
| // Check if CSRF protection is enabled, either on the parent controller or from the default setting. Note that | ||
| // method_exists() is used as some controllers (e.g. GroupTest) do not always extend from Object. | ||
|
|
@@ -1790,6 +1792,21 @@ public function removeExtraClass($class) | |
| return $this; | ||
| } | ||
|
|
||
| public function __clone(): void | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See usage in |
||
| { | ||
| $this->fields = clone $this->fields; | ||
| $this->actions = clone $this->actions; | ||
| if ($this->validator) { | ||
| $this->setValidator(clone $this->validator); | ||
| } | ||
| foreach ($this->fields as $field) { | ||
| $field->setForm($this); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this recursive? e.g. will field groups and composite fields ensure their descendants call $field->setForm() properly? I'd kind of expect this to happen in the FieldList cloning you mentioned in the comment above, so I'm a little surprised to see it here
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| foreach ($this->actions as $action) { | ||
| $action->setForm($this); | ||
| } | ||
| } | ||
|
|
||
| public function debug(): string | ||
| { | ||
| $class = static::class; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,16 +4,15 @@ | |
|
|
||
| use BadMethodCallException; | ||
| use SilverStripe\Control\Controller; | ||
| use SilverStripe\Control\Director; | ||
| use SilverStripe\Control\HTTPRequest; | ||
| use SilverStripe\Control\HTTPResponse; | ||
| use SilverStripe\Control\HTTPResponse_Exception; | ||
| use SilverStripe\Control\RequestHandler; | ||
| use SilverStripe\Core\ClassInfo; | ||
| use SilverStripe\Core\Convert; | ||
| use SilverStripe\Core\Validation\ValidationResult; | ||
| use SilverStripe\Model\List\SS_List; | ||
| use SilverStripe\Core\Validation\ValidationException; | ||
| use SilverStripe\Forms\Schema\FormSchema; | ||
|
|
||
| class FormRequestHandler extends RequestHandler | ||
| { | ||
|
|
@@ -27,6 +26,7 @@ class FormRequestHandler extends RequestHandler | |
| * @var array | ||
| */ | ||
| private static $allowed_actions = [ | ||
| 'getSchema', | ||
| 'handleField', | ||
| 'httpSubmission', | ||
| 'forTemplate', | ||
|
|
@@ -37,6 +37,7 @@ class FormRequestHandler extends RequestHandler | |
| * @var array | ||
| */ | ||
| private static $url_handlers = [ | ||
| 'GET schema' => 'getSchema', | ||
| 'field/$FieldName!' => 'handleField', | ||
| 'POST ' => 'httpSubmission', | ||
| 'GET ' => 'httpSubmission', | ||
|
|
@@ -67,6 +68,18 @@ public function __construct(Form $form) | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets a JSON schema representing a form. | ||
| */ | ||
| public function getSchema(HTTPRequest $request): HTTPResponse | ||
| { | ||
| $schemaID = $request->getURL(); | ||
| $parts = $request->getHeader(FormSchema::SCHEMA_HEADER); | ||
| $data = FormSchema::singleton()->getMultipartSchema($parts, $schemaID, $this->form); | ||
| $response = HTTPResponse::create(json_encode($data)); | ||
| $response->addHeader('Content-Type', 'application/json'); | ||
| return $response; | ||
| } | ||
|
Comment on lines
+71
to
+82
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works very similar to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the bulk of this could be moved into
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't worry above it, the fact that |
||
|
|
||
| /** | ||
| * Get link for this 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.
$controlleris optional - but needs to be available and set in this form for form state to be recoverable. This is technically a bugfix but in reality we only really run into it when setting up test forms.