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 Make LinkFieldController a subclass of FormSchemaController #348

Merged
merged 1 commit into from
Nov 19, 2024
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
6 changes: 2 additions & 4 deletions src/Controllers/LinkFieldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SilverStripe\LinkField\Controllers;

use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Admin\FormSchemaController;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Forms\DefaultFormFactory;
use SilverStripe\Forms\Form;
Expand All @@ -25,14 +25,12 @@
use SilverStripe\ORM\Queries\SQLUpdate;
use SilverStripe\Versioned\Versioned;

class LinkFieldController extends LeftAndMain
class LinkFieldController extends FormSchemaController
{
public const FORM_NAME_TEMPLATE = 'LinkForm_%s';

private static string $url_segment = 'linkfield';

private static $ignore_menuitem = true;

private static array $url_handlers = [
'linkForm/$ItemID' => 'linkForm',
'GET data/$ItemID' => 'linkData',
Expand Down
6 changes: 3 additions & 3 deletions tests/php/Controllers/LinkFieldControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ public function testLinkFormPost(
$response = $this->post($url, $data, $headers);
$this->assertSame($expectedCode, $response->getStatusCode());
if ($fail === 'csrf-token') {
// Will end up at an HTML page with "Silverstripe - Bad Request"
$this->assertSame('text/html; charset=utf-8', $response->getHeader('Content-type'));
$this->assertStringContainsString('Silverstripe - Bad Request', $response->getBody());
// Gives suitable error message for XHR request
$this->assertStringStartsWith('text/plain', $response->getHeader('Content-type'));
$this->assertStringContainsString('There seems to have been a technical problem', $response->getBody());
Comment on lines -254 to +256
Copy link
Member Author

@GuySartorelli GuySartorelli Nov 14, 2024

Choose a reason for hiding this comment

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

The modal links used to be routed through LeftAndMain which meant the error handling in that class was used. For some reason they weren't picked up as XHR requests so the full HTML error page was being rendered which wasn't really the correct behaviour, but it's what happened.

Now, a simple 400 response (the default one produced when a form's CSRF token is missing) is produced and isn't altered. This is the correct behaviour.

The end result for the user is no change.

return;
}
$this->assertSame($expectedCode, $response->getStatusCode());
Expand Down
Loading