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

ENH CMS 6 compatibility #346

Open
wants to merge 1 commit into
base: 3.0
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Silverstripe Campaign Admin Module

[![CI](https://github.com/silverstripe/silverstripe-campaign-admin/actions/workflows/ci.yml/badge.svg)](https://github.com/silverstripe/silverstripe-campaign-admin/actions/workflows/ci.yml)
[![Silverstripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)

## Overview

Expand Down
10 changes: 7 additions & 3 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ SilverStripe\Admin\LeftAndMain:
extra_requirements_css:
- 'silverstripe/campaign-admin: client/dist/styles/bundle.css'

SilverStripe\CMS\Model\SiteTree:
extensions:
- SilverStripe\CampaignAdmin\SiteTreeExtension
# Allow users only only have access to the campaign-admin, and not all CMS access
# i.e. CMS_ACCESS_LeftAndMain, to still be able to manage changesets
SilverStripe\Versioned\ChangeSet:
Copy link
Member Author

Choose a reason for hiding this comment

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

These used to be done in Versioned silverstripe/silverstripe-versioned#482

The plural_name is used here with a call to ChangeSet::singleton()->i18n_pluralise()

We may as well also keep the singlular_name for consistency

required_permission:
- CMS_ACCESS_CampaignAdmin
singular_name: 'Campaign'
plural_name: 'Campaigns'
39 changes: 39 additions & 0 deletions _config/extensions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
Name: campaign-admin-extensions
---
SilverStripe\Assets\Shortcodes\FileLink:
extensions:
- SilverStripe\CampaignAdmin\Extensions\HideInCampaignsExtension
---
Name: campaign-admin-extensions-elemental
Only:
moduleexists: dnadesign/silverstripe-elemental
---
DNADesign\Elemental\Models\ElementalArea:
extensions:
- SilverStripe\CampaignAdmin\Extensions\HideInCampaignsExtension
---
Name: campaign-admin-extensions-asset-admin
Only:
moduleexists: silverstripe/asset-admin
After: assetadmin
---
SilverStripe\AssetAdmin\Forms\FileFormFactory:
extensions:
- SilverStripe\CampaignAdmin\Extensions\FileFormFactoryExtension
SilverStripe\AssetAdmin\Controller\AssetAdmin:
campaign_admin_managed_data_class: SilverStripe\Assets\File
extensions:
- SilverStripe\CampaignAdmin\Extensions\AddToCampaignExtension
---
Name: campaign-admin-extensions-cms
Only:
moduleexists: silverstripe/cms
---
SilverStripe\CMS\Model\SiteTree:
extensions:
- SilverStripe\CampaignAdmin\SiteTreeExtension
SilverStripe\CMS\Controllers\CMSPageEditController:
campaign_admin_managed_data_class: Page
extensions:
- SilverStripe\CampaignAdmin\Extensions\AddToCampaignExtension
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion client/src/bundles/bundle.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require('../boot/index');
import '../legacy/AddToCampaignForm';
import '../boot/index';
108 changes: 108 additions & 0 deletions client/src/legacy/AddToCampaignForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* global window */
Copy link
Member Author

Choose a reason for hiding this comment

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

This is JS that used to be in admin silverstripe/silverstripe-admin#1857

import i18n from 'i18n';
import jQuery from 'jquery';
import React from 'react';
import { createRoot } from 'react-dom/client';
import { loadComponent } from 'lib/Injector';

const FormBuilderModal = loadComponent('FormBuilderModal');

jQuery.entwine('ss', ($) => {
/**
* Kick off an "add to campaign" dialog from the CMS actions.
*/
$(
'.cms-content-actions .add-to-campaign-action,' +
'#add-to-campaign__action'
).entwine({
onclick() {
let dialog = $('#add-to-campaign__dialog-wrapper');

if (!dialog.length) {
dialog = $('<div id="add-to-campaign__dialog-wrapper" />');
$('body').append(dialog);
}

dialog.open();

return false;
},
});

// This is required because the React version of e.preventDefault() doesn't work
// this is to prevent PJAX request to occur when clicking a link the modal
$('.add-to-campaign-modal .add-to-campaign-modal__nav-link').entwine({
onclick: (e) => {
e.preventDefault();
const $link = $(e.target);
window.location = $link.attr('href');
},
});

/**
* Uses reactstrap in order to replicate the bootstrap styling and JavaScript behaviour.
* The "add to campaign" dialog is used in a similar fashion in AssetAdmin.
*/
$('#add-to-campaign__dialog-wrapper').entwine({
ReactRoot: null,

onunmatch() {
// solves errors given by ReactDOM "no matched root found" error.
this._clearModal();
},

open() {
this._renderModal(true);
},

close() {
this._renderModal(false);
},

_renderModal(isOpen) {
const handleHide = () => this.close();
const handleSubmit = (...args) => this._handleSubmitModal(...args);
const id = $('form.cms-edit-form :input[name=ID]').val();
const sectionConfigKey = 'SilverStripe\\CMS\\Controllers\\CMSPageEditController';
const store = window.ss.store;
const sectionConfig = store.getState().config.sections
.find((section) => section.name === sectionConfigKey);
const modalSchemaUrl = `${sectionConfig.form.addToCampaignForm.schemaUrl}/${id}`;
const title = i18n._t('Admin.ADD_TO_CAMPAIGN', 'Add to campaign');

let root = this.getReactRoot();
if (!root) {
root = createRoot(this[0]);
}
root.render(
<FormBuilderModal
title={title}
isOpen={isOpen}
onSubmit={handleSubmit}
onClosed={handleHide}
schemaUrl={modalSchemaUrl}
bodyClassName="modal__dialog"
className="add-to-campaign-modal"
responseClassBad="modal__response modal__response--error"
responseClassGood="modal__response modal__response--good"
identifier="Admin.AddToCampaign"
/>
);
this.setReactRoot(root);
},

_clearModal() {
const root = this.getReactRoot();
if (root) {
root.unmount();
this.setReactRoot(null);
}
// this.empty();
},

_handleSubmitModal(data, action, submitFn) {
return submitFn();
},

});
});
59 changes: 0 additions & 59 deletions client/src/state/campaign/tests/CampaignActions-test.js

This file was deleted.

3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"php": "^8.3",
"silverstripe/admin": "^3",
"silverstripe/framework": "^6",
"silverstripe/versioned": "^3",
"silverstripe/vendor-plugin": "^2"
Copy link
Member Author

Choose a reason for hiding this comment

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

Using the vendor-plugin defined in framework instead

"silverstripe/versioned": "^3"
},
"require-dev": {
"phpunit/phpunit": "^11.3",
Expand Down
19 changes: 7 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,20 @@
"homepage": "https://github.com/silverstripe/silverstripe-campaign-admin",
"dependencies": {
"@popperjs/core": "^2.11.6",
"bootstrap": "^4.6.2",
"bootstrap": "^5.2.0",
"classnames": "^2.3.2",
"core-js": "^3.26.0",
"deep-freeze-strict": "^1.1.1",
"prop-types": "^15.8.1",
"react": "^18.2.0",
Copy link
Member Author

@emteknetnz emteknetnz Mar 5, 2025

Choose a reason for hiding this comment

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

Removed all of the react* deps because they're not needed as it'll automatically just use the deps from admin, and also because I could could not run yarn build with them here as they causes the 'Invalid hook call' issue.

Copy link
Member

Choose a reason for hiding this comment

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

I assume you mean "because I couldn't run yarn build with them there"

"react-dom": "^18.2.0",
"react-redux": "^8.0.5",
"react-router-dom": "^6.4.3",
"reactstrap": "^8.9.0",
"redux": "^4.2.0",
"redux-form": "^8.3.8",
"redux-mock-store": "^1.5.4",
"redux-thunk": "^2.4.2"
"reactstrap": "^9.2.0",
"redux": "^5.0.1",
"redux-form": "^8.3.10",
"redux-thunk": "^3.1.0"
},
"devDependencies": {
"@silverstripe/eslint-config": "^1.3.0",
"@silverstripe/webpack-config": "^3.0.0-alpha1",
"@testing-library/react": "^14.0.0",
"@silverstripe/webpack-config": "^3.0.0-alpha3",
"@testing-library/react": "^16.1.0",
"babel-core": "^6.26.3",
"babel-jest": "^29.3.0",
"babel-loader": "^9.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/AddToCampaignValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SilverStripe\CampaignAdmin;

use SilverStripe\Forms\Validator;
use SilverStripe\Forms\Validation\Validator;

class AddToCampaignValidator extends Validator
{
Expand Down
7 changes: 3 additions & 4 deletions src/CampaignAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\Validation\RequiredFieldsValidator;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Model\List\SS_List;
Expand Down Expand Up @@ -637,7 +636,7 @@ public function getCampaignEditForm($id)
FormAction::create('cancel', _t(__CLASS__.'.CANCEL', 'Cancel'))
->setUseButtonTag(true)
),
new RequiredFields('Name')
RequiredFieldsValidator::create('Name')
);

// Load into form
Expand Down Expand Up @@ -701,7 +700,7 @@ public function getCampaignCreateForm()
FormAction::create('cancel', _t(__CLASS__.'.CANCEL', 'Cancel'))
->setUseButtonTag(true)
),
new RequiredFields('Name')
RequiredFieldsValidator::create('Name')
);

// Custom form handler
Expand Down
Loading
Loading