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 Remove silverstripe/campaign-admin integration support #1512

Merged
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
8 changes: 0 additions & 8 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ SilverStripe\Core\Injector\Injector:
SilverStripe\Forms\FileHandleField:
class: SilverStripe\AssetAdmin\Forms\UploadField
---
Name: assetadmincampaigns
Only:
moduleexists: 'silverstripe/campaign-admin'
---
SilverStripe\AssetAdmin\Forms\FileFormFactory:
extensions:
- 'SilverStripe\AssetAdmin\Extensions\CampaignAdminExtension'
---
Name: assetadminmodals
---
SilverStripe\Admin\ModalController:
Expand Down
2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_sslink-file.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_ssmedia.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion client/src/containers/AssetAdmin/AssetAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,6 @@ class AssetAdmin extends Component {
onClose: this.handleCloseFile,
onSubmit: this.handleSubmitEditor,
onUnpublish: this.handleUnpublish,
addToCampaignSchemaUrl: config.form.addToCampaignForm.schemaUrl
};

return <EditorComponent {...editorProps} />;
Expand Down
3 changes: 0 additions & 3 deletions client/src/containers/AssetAdmin/tests/AssetAdmin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ function makeProps(obj = {}) {
fileSearchForm: {
schemaUrl: '',
},
addToCampaignForm: {
schemaUrl: '',
}
},
},
fileId: null,
Expand Down
36 changes: 1 addition & 35 deletions client/src/containers/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { bindActionCreators, compose } from 'redux';
import React, { Component } from 'react';
import CONSTANTS from 'constants/index';
import FormBuilderLoader from 'containers/FormBuilderLoader/FormBuilderLoader';
import FormBuilderModal from 'components/FormBuilderModal/FormBuilderModal';
import * as UnsavedFormsActions from 'state/unsavedForms/UnsavedFormsActions';
import PropTypes from 'prop-types';
import { inject } from 'lib/Injector';
Expand All @@ -32,13 +31,10 @@ class Editor extends Component {
this.handleLoadingSuccess = this.handleLoadingSuccess.bind(this);
this.handleLoadingError = this.handleLoadingError.bind(this);
this.handleFetchingSchema = this.handleFetchingSchema.bind(this);
this.closeModal = this.closeModal.bind(this);
this.openModal = this.openModal.bind(this);
this.createFn = this.createFn.bind(this);
this.editorHeader = this.editorHeader.bind(this);

this.state = {
openModal: false,
loadingForm: false,
loadingError: null,
file: null,
Expand Down Expand Up @@ -91,12 +87,6 @@ class Editor extends Component {
handleAction(event) {
const file = this.state.file;
switch (event.currentTarget.name) {
// intercept the Add to Campaign submit and open the modal dialog instead
case 'action_addtocampaign':
this.openModal();
event.preventDefault();

break;
case 'action_replacefile':
this.replaceFile();
event.preventDefault();
Expand Down Expand Up @@ -162,22 +152,13 @@ class Editor extends Component {
} else {
// If we're already at the top of the form stack, close the editor form
onClose();
this.closeModal();
}

if (event) {
event.preventDefault();
}
}

openModal() {
this.setState({ openModal: true });
}

closeModal() {
this.setState({ openModal: false });
}

replaceFile() {
const hiddenFileInput = document.querySelector('.dz-input-PreviewImage');

Expand Down Expand Up @@ -289,9 +270,8 @@ class Editor extends Component {
if (!this.state.file) {
return null;
}
const { FormBuilderLoaderComponent, FormBuilderModalComponent } = this.props;
const { FormBuilderLoaderComponent } = this.props;
const formSchemaUrl = this.getFormSchemaUrl();
const modalSchemaUrl = `${this.props.addToCampaignSchemaUrl}/${this.props.fileId}`;
const editorClasses = classnames(
'panel', 'form--no-dividers', 'editor', {
'editor--asset-dropzone--disable': !this.props.enableDropzone
Expand All @@ -311,7 +291,6 @@ class Editor extends Component {
<div className="editor__file-preview-message--file-missing">{message}</div>
);
}
const campaignTitle = i18n._t('Admin.ADD_TO_CAMPAIGN', 'Add to campaign');
const Loading = this.props.loadingComponent;

return (<div className={editorClasses}>
Expand All @@ -328,16 +307,6 @@ class Editor extends Component {
file={this.state.file}
/>
{error}
<FormBuilderModalComponent
title={campaignTitle}
identifier="AssetAdmin.AddToCampaign"
isOpen={this.state.openModal}
onClosed={this.closeModal}
schemaUrl={modalSchemaUrl}
bodyClassName="modal__dialog"
responseClassBad="modal__response modal__response--error"
responseClassGood="modal__response modal__response--good"
/>
{ this.state.loadingForm && <Loading />}
</div>
</div>);
Expand All @@ -356,19 +325,16 @@ Editor.propTypes = {
name: PropTypes.string,
value: PropTypes.any,
})),
addToCampaignSchemaUrl: PropTypes.string,
actions: PropTypes.object,
showingSubForm: PropTypes.bool,
nextType: PropTypes.string,
EditorHeaderComponent: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
FormBuilderLoaderComponent: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
FormBuilderModalComponent: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
};

Editor.defaultProps = {
EditorHeaderComponent: EditorHeader,
FormBuilderLoaderComponent: FormBuilderLoader,
FormBuilderModalComponent: FormBuilderModal,
};

function mapDispatchToProps(dispatch) {
Expand Down
36 changes: 10 additions & 26 deletions client/src/containers/Editor/tests/Editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,12 @@ function makeProps(obj = {}) {
FormBuilderLoaderComponent: ({ createFn, onAction, schemaUrl }) => (
<div data-testid="test-form-builder-loader" onClick={() => onAction(...nextParams)} data-schema-url={schemaUrl}>{createFn(...createFnParams)}</div>
),
FormBuilderModalComponent: ({ isOpen }) => <div data-testid="test-form-builder-modal" data-is-open={isOpen}/>,
...obj
};
}

async function openModal() {
const loader = await screen.findByTestId('test-form-builder-loader');
nextParams = [{
preventDefault: () => null,
currentTarget: {
name: 'action_addtocampaign'
}
}];
fireEvent.click(loader);
async function awaitLoader() {
await screen.findByTestId('test-form-builder-loader');
nextParams = [{
preventDefault: () => null,
currentTarget: {
Expand All @@ -117,16 +109,12 @@ test('Editor handleClose Closing editor', async () => {
/>
);
resolveBackendGet(makeReadFileResponse());
openModal();
let modal = await screen.findByTestId('test-form-builder-modal');
expect(modal.getAttribute('data-is-open')).toBe('true');
awaitLoader();
const header = await screen.findByTestId('test-editor-header');
nextAction = 'cancel';
fireEvent.click(header);
expect(popFormStackEntry).not.toHaveBeenCalled();
expect(onClose).toHaveBeenCalled();
modal = await screen.findByTestId('test-form-builder-modal');
expect(modal.getAttribute('data-is-open')).toBe('false');
expect(header.getAttribute('data-show-button')).toBe(buttonStates.SWITCH);
});

Expand All @@ -147,16 +135,12 @@ test('Editor handleClose Closing sub form', async () => {
/>
);
resolveBackendGet(makeReadFileResponse());
openModal();
let modal = await screen.findByTestId('test-form-builder-modal');
expect(modal.getAttribute('data-is-open')).toBe('true');
awaitLoader();
const header = await screen.findByTestId('test-editor-header');
nextAction = 'cancel';
fireEvent.click(header);
expect(popFormStackEntry).toHaveBeenCalled();
expect(onClose).not.toHaveBeenCalled();
modal = await screen.findByTestId('test-form-builder-modal');
expect(modal.getAttribute('data-is-open')).toBe('true');
expect(header.getAttribute('data-show-button')).toBe(buttonStates.SWITCH);
});

Expand Down Expand Up @@ -189,7 +173,7 @@ test('Editor editorHeader Top Form with detail in dialog', async () => {
/>
);
resolveBackendGet(makeReadFileResponse());
openModal();
awaitLoader();
const header = await screen.findByTestId('test-editor-header');
nextAction = 'details';
fireEvent.click(header);
Expand All @@ -208,7 +192,7 @@ test('Editor editorHeader Sub form in dialog', async () => {
/>
);
resolveBackendGet(makeReadFileResponse());
openModal();
awaitLoader();
const header = await screen.findByTestId('test-editor-header');
expect(header.getAttribute('data-show-button')).toBe(buttonStates.ALWAYS_BACK);
});
Expand All @@ -228,7 +212,7 @@ test('Editor editorHeader Form for folder', async () => {
type: 'folder',
})
});
openModal();
awaitLoader();
const header = await screen.findByTestId('test-editor-header');
expect(header.getAttribute('data-show-button')).toBe(buttonStates.SWITCH);
});
Expand All @@ -242,7 +226,7 @@ test('Editor getFormSchemaUrl Plain URL', async () => {
/>
);
resolveBackendGet(makeReadFileResponse());
openModal();
awaitLoader();
const loader = await screen.findByTestId('test-form-builder-loader');
expect(loader.getAttribute('data-schema-url')).toBe('edit/file/123');
});
Expand All @@ -256,7 +240,7 @@ test('Editor getFormSchemaUrl Plain URL', async () => {
/>
);
resolveBackendGet(makeReadFileResponse());
openModal();
awaitLoader();
const loader = await screen.findByTestId('test-form-builder-loader');
expect(loader.getAttribute('data-schema-url')).toBe('edit/file/123?q=search');
});
Expand All @@ -273,7 +257,7 @@ test('Editor getFormSchemaUrl Plain URL', async () => {
/>
);
resolveBackendGet(makeReadFileResponse());
openModal();
awaitLoader();
const loader = await screen.findByTestId('test-form-builder-loader');
expect(loader.getAttribute('data-schema-url')).toBe('edit/file/123?q=search&foo=bar');
});
83 changes: 0 additions & 83 deletions code/Controller/AssetAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use SilverStripe\Assets\Image;
use SilverStripe\Assets\Storage\AssetNameGenerator;
use SilverStripe\Assets\Upload;
use SilverStripe\CampaignAdmin\AddToCampaignHandler;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
Expand Down Expand Up @@ -97,7 +96,6 @@ class AssetAdmin extends AssetAdminOpen implements PermissionProvider
'folderCreateForm',
'fileEditForm',
'fileHistoryForm',
'addToCampaignForm',
'fileInsertForm',
'fileEditorLinkForm',
'schema',
Expand Down Expand Up @@ -292,9 +290,6 @@ public function getClientConfig(): array
'fileSelectForm' => [
'schemaUrl' => $this->Link('schema/fileSelectForm')
],
'addToCampaignForm' => [
'schemaUrl' => $this->Link('schema/addToCampaignForm')
],
'fileHistoryForm' => [
'schemaUrl' => $this->Link('schema/fileHistoryForm')
],
Expand Down Expand Up @@ -1425,84 +1420,6 @@ public function generateThumbnails(File $file, $thumbnailLinks = false)
return $links;
}

/**
* Action handler for adding pages to a campaign
*
* @deprecated 2.4.0 Will be removed without equivalent functionality to replace it
*/
public function addtocampaign(array $data, Form $form): HTTPResponse
{
Deprecation::noticeWithNoReplacment('2.4.0');
$id = $data['ID'];
$record = File::get()->byID($id);

$handler = AddToCampaignHandler::create($this, $record, 'addToCampaignForm');
$response = $handler->addToCampaign($record, $data);
$message = $response->getBody();
if (empty($message)) {
return $response;
}

// Send extra "message" data with schema response
$extraData = ['message' => $message];
$schemaId = Controller::join_links($this->Link('schema/addToCampaignForm'), $id);
return $this->getSchemaResponse($schemaId, $form, null, $extraData);
}

/**
* Url handler for add to campaign form
*
* @param HTTPRequest $request
* @return Form
* @deprecated 2.4.0 Will be removed without equivalent functionality to replace it
*/
public function addToCampaignForm($request)
{
Deprecation::noticeWithNoReplacment('2.4.0');
// Get ID either from posted back value, or url parameter
$id = $request->param('ID') ?: $request->postVar('ID');
return $this->getAddToCampaignForm($id);
}

/**
* @param int $id
* @return Form|HTTPResponse
* @deprecated 2.4.0 Will be removed without equivalent functionality to replace it
*/
public function getAddToCampaignForm($id)
{
Deprecation::noticeWithNoReplacment('2.4.0');
// Get record-specific fields
$record = File::get()->byID($id);

if (!$record) {
$this->jsonError(404, _t(
__CLASS__.'.ErrorNotFound',
"That {Type} couldn't be found",
['Type' => File::singleton()->i18n_singular_name()]
));
return null;
}
if (!$record->canView()) {
$this->jsonError(403, _t(
__CLASS__.'.ErrorItemPermissionDenied',
"You don't have the necessary permissions to modify {ObjectTitle}",
['ObjectTitle' => $record->i18n_singular_name()]
));
return null;
}

$handler = AddToCampaignHandler::create($this, $record, 'addToCampaignForm');
$form = $handler->Form($record);

$form->setValidationResponseCallback(function (ValidationResult $errors) use ($form, $id) {
$schemaId = Controller::join_links($this->Link('schema/addToCampaignForm'), $id);
return $this->getSchemaResponse($schemaId, $form, $errors);
});

return $form;
}

/**
* @return Upload
*/
Expand Down
Loading