Skip to content

Commit

Permalink
API Avoid reimplementing logic from ModalController
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 27, 2024
1 parent 1be8a05 commit 2a5c58b
Showing 1 changed file with 2 additions and 53 deletions.
55 changes: 2 additions & 53 deletions code/Extensions/RemoteFileModalExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@

use Embed\Http\NetworkException;
use Embed\Http\RequestException;
use SilverStripe\Admin\FormSchemaController;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Admin\ModalController;
use SilverStripe\AssetAdmin\Forms\RemoteFileFormFactory;
use SilverStripe\AssetAdmin\Exceptions\InvalidRemoteUrlException;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Extension;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\Schema\FormSchema;
use SilverStripe\Core\Validation\ValidationResult;

/**
Expand All @@ -33,26 +28,6 @@ class RemoteFileModalExtension extends Extension
'remoteEditFormSchema',
);

/**
* @return HTTPRequest
* @deprecated 2.4.0 Use $this->getOwner()->getRequest() instead.
*/
protected function getRequest()
{
Deprecation::notice('2.4.0', 'Use $this->getOwner()->getRequest() instead.');
return $this->getOwner()->getRequest();
}

/**
* @return FormSchema
* @deprecated 2.4.0 Will be removed without equivalent functionality to replace it.
*/
protected function getFormSchema()
{
Deprecation::noticeWithNoReplacment('2.4.0');
return FormSchema::singleton();
}

/**
* Form for creating a new OEmbed object in the WYSIWYG, used by the InsertEmbedModal component
*
Expand Down Expand Up @@ -97,7 +72,7 @@ public function remoteEditFormSchema(HTTPRequest $request)
$schemaID = $request->getURL();
try {
$form = $this->remoteEditForm();
return $this->getSchemaResponse($schemaID, $form);
return $this->getOwner()->getSchemaResponse($schemaID, $form);
} catch (NetworkException | RequestException | InvalidRemoteUrlException $exception) {
$errors = ValidationResult::create()
->addError($exception->getMessage());
Expand All @@ -109,35 +84,9 @@ public function remoteEditFormSchema(HTTPRequest $request)
}

return $this
->getOwner()
->getSchemaResponse($schemaID, $form, $errors)
->setStatusCode($code);
}
}

/**
* Generate schema for the given form based on the X-Formschema-Request header value
*
* @param string $schemaID ID for this schema. Required.
* @param Form $form Required for 'state' or 'schema' response
* @param ValidationResult $errors Required for 'error' response
* @param array $extraData Any extra data to be merged with the schema response
* @return HTTPResponse
* @deprecated 2.4.0 Will be replaced with $this->getOwner()->getSchemaResponse() instead.
*/
protected function getSchemaResponse($schemaID, $form = null, ValidationResult $errors = null, $extraData = [])
{
Deprecation::noticeWithNoReplacment('2.4.0', 'Will be replaced with $this->getOwner()->getSchemaResponse() instead.');
$parts = $this->getOwner()->getRequest()->getHeader(FormSchemaController::SCHEMA_HEADER);
$data = $this
->getFormSchema()
->getMultipartSchema($parts, $schemaID, $form, $errors);

if ($extraData) {
$data = array_merge($data, $extraData);
}

$response = new HTTPResponse(json_encode($data));
$response->addHeader('Content-Type', 'application/json');
return $response;
}
}

0 comments on commit 2a5c58b

Please sign in to comment.