Skip to content

Commit

Permalink
Merge pull request #20392 from seamuslee001/ckeditor4
Browse files Browse the repository at this point in the history
[REF] Extract CKEditor into its own core extension
  • Loading branch information
eileenmcnaughton authored Jul 7, 2021
2 parents 42ab5fa + 301b8b4 commit ddca977
Show file tree
Hide file tree
Showing 25 changed files with 2,020 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
!/ext/contributioncancelactions
!/ext/recaptcha
!/ext/payflowpro
!/ext/ckeditor4
backdrop/
bower_components
CRM/Case/xml/configuration
Expand Down
12 changes: 0 additions & 12 deletions CRM/Core/Resources/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,6 @@ protected static function coreResourceList($region) {
'moneyFormat' => CRM_Utils_Money::format(1234.56),
]);

// add wysiwyg editor
$editor = $settings->get('editor_id');
if ($editor == "CKEditor") {
CRM_Admin_Form_CKEditorConfig::setConfigDefault();
$items[] = [
'config' => [
'wysisygScriptLocation' => Civi::paths()->getUrl("[civicrm.root]/js/wysiwyg/crm.ckeditor.js"),
'CKEditorCustomConfig' => CRM_Admin_Form_CKEditorConfig::getConfigUrl(),
],
];
}

// These scripts are only needed by back-office users
if (CRM_Core_Permission::check('access CiviCRM')) {
$items[] = "packages/jquery/plugins/jquery.tableHeader.js";
Expand Down
6 changes: 0 additions & 6 deletions CRM/Core/xml/Menu/Admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,4 @@
<page_callback>CRM_Badge_Form_Layout</page_callback>
<access_arguments>administer CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/admin/ckeditor</path>
<title>Configure CKEditor</title>
<page_callback>CRM_Admin_Form_CKEditorConfig</page_callback>
<access_arguments>administer CiviCRM</access_arguments>
</item>
</menu>
42 changes: 42 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveForty.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function upgrade_5_40_alpha1($rev) {
$this->addTask('Add membership_num_terms column to civicrm_line_item', 'addColumn',
'civicrm_line_item', 'membership_num_terms', "int unsigned DEFAULT NULL COMMENT 'Number of terms for this membership (only supported in Order->Payment flow). If the field is NULL it means unknown and it will be assumed to be 1 during payment.create if entity_table is civicrm_membership'"
);
$this->addTask('Enable new CKEditor 4 Extension', 'installCkeditor4Extension');
$this->addTask('Update CKeditor label to indicate it is version 4', 'updateCkeditorOptionLabel');
}

/**
Expand Down Expand Up @@ -100,4 +102,44 @@ public static function addContributionProductFK(CRM_Queue_TaskContext $ctx): boo
return TRUE;
}

/**
* @param CRM_Queue_TaskContext $ctx
* @return bool
*/
public static function updateCkeditorOptionLabel(CRM_Queue_TaskContext $ctx) {
civicrm_api3('OptionValue', 'get', [
'name' => 'CKEditor',
'option_group_id' => 'wysiwyg_editor',
'api.OptionValue.create' => [
'label' => ts('CKEditor 4'),
'id' => "\$value.id",
],
]);
return TRUE;
}

/**
* Install CKEditor4 extension.
*
* @param \CRM_Queue_TaskContext $ctx
*
* @return bool
*
* @throws \CRM_Core_Exception
*/
public static function installCkeditor4Extension(CRM_Queue_TaskContext $ctx) {
$insert = CRM_Utils_SQL_Insert::into('civicrm_extension')->row([
'type' => 'module',
'full_name' => 'ckeditor4',
'name' => 'CKEditor4',
'label' => 'CKEditor4',
'file' => 'ckeditor4',
'schema_version' => NULL,
'is_active' => 1,
]);
CRM_Core_DAO::executeQuery($insert->usingReplace()->toSQL());

return TRUE;
}

}
2 changes: 1 addition & 1 deletion bin/regen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ php GenerateData.php

## Prune local data
$MYSQLCMD -e "DROP TABLE IF EXISTS civicrm_install_canary; DELETE FROM civicrm_cache; DELETE FROM civicrm_setting;"
$MYSQLCMD -e "DELETE FROM civicrm_extension WHERE full_name NOT IN ('sequentialcreditnotes', 'eventcart', 'greenwich', 'search', 'flexmailer', 'financialacls', 'contributioncancelactions', 'recaptcha');"
$MYSQLCMD -e "DELETE FROM civicrm_extension WHERE full_name NOT IN ('sequentialcreditnotes', 'eventcart', 'greenwich', 'search', 'flexmailer', 'financialacls', 'contributioncancelactions', 'recaptcha', 'ckeditor4');"
TABLENAMES=$( echo "show tables like 'civicrm_%'" | $MYSQLCMD | grep ^civicrm_ | xargs )

cd $CIVISOURCEDIR/sql
Expand Down
1 change: 1 addition & 0 deletions distmaker/core-ext.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
afform
authx
contributioncancelactions
ckeditor4
eventcart
ewaysingle
financialacls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

use CRM_Ckeditor4_ExtensionUtil as E;

/**
* Form for configuring CKEditor options.
*/
class CRM_Admin_Form_CKEditorConfig extends CRM_Core_Form {
class CRM_Ckeditor4_Form_CKEditorConfig extends CRM_Core_Form {

const CONFIG_FILEPATH = '[civicrm.files]/persist/crm-ckeditor-';

Expand Down Expand Up @@ -79,7 +81,7 @@ public function addResources() {
->addScriptFile('civicrm', 'bower_components/ckeditor/samples/toolbarconfigurator/js/fulltoolbareditor.js', 1)
->addScriptFile('civicrm', 'bower_components/ckeditor/samples/toolbarconfigurator/js/abstracttoolbarmodifier.js', 2)
->addScriptFile('civicrm', 'bower_components/ckeditor/samples/toolbarconfigurator/js/toolbarmodifier.js', 3)
->addScriptFile('civicrm', 'js/wysiwyg/admin.ckeditor-configurator.js', 10)
->addScriptFile('ckeditor4', 'js/admin.ckeditor-configurator.js', 10)
->addStyleFile('civicrm', 'bower_components/ckeditor/samples/toolbarconfigurator/css/fontello.css')
->addStyleFile('civicrm', 'bower_components/ckeditor/samples/css/samples.css')
->addVars('ckConfig', [
Expand Down Expand Up @@ -162,7 +164,7 @@ public function save($params) {
. preg_replace('~\R~u', "\n", $params['config']);

// Generate a whitelist of allowed config params
$allOptions = json_decode(file_get_contents(\Civi::paths()->getPath('[civicrm.root]/js/wysiwyg/ck-options.json')), TRUE);
$allOptions = json_decode(file_get_contents(E::path('js/ck-options.json')), TRUE);
// These two aren't really blacklisted they're just in a different part of the form
$blackList = array_diff($this->blackList, ['skin', 'extraPlugins']);
// All options minus blacklist = whitelist
Expand Down
147 changes: 147 additions & 0 deletions ext/ckeditor4/CRM/Ckeditor4/Upgrader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php
use CRM_Ckeditor4_ExtensionUtil as E;

/**
* Collection of upgrade steps.
*/
class CRM_Ckeditor4_Upgrader extends CRM_Ckeditor4_Upgrader_Base {

// By convention, functions that look like "function upgrade_NNNN()" are
// upgrade tasks. They are executed in order (like Drupal's hook_update_N).

/**
* Example: Run an external SQL script when the module is installed.
*/
public function install() {
CRM_Core_BAO_OptionValue::ensureOptionValueExists([
'option_group_id' => 'wysiwyg_editor',
'label' => E::ts('CKEditor 4'),
'name' => 'CKEditor',
'is_default' => 1,
]);
}

/**
* Example: Work with entities usually not available during the install step.
*
* This method can be used for any post-install tasks. For example, if a step
* of your installation depends on accessing an entity that is itself
* created during the installation (e.g., a setting or a managed entity), do
* so here to avoid order of operation problems.
*/
// public function postInstall() {
// $customFieldId = civicrm_api3('CustomField', 'getvalue', array(
// 'return' => array("id"),
// 'name' => "customFieldCreatedViaManagedHook",
// ));
// civicrm_api3('Setting', 'create', array(
// 'myWeirdFieldSetting' => array('id' => $customFieldId, 'weirdness' => 1),
// ));
// }

/**
* Example: Run an external SQL script when the module is uninstalled.
*/
public function uninstall() {
$domains = civicrm_api3('Domain', 'get', ['options' => ['limit' => 0]])['values'];
foreach ($domains as $domain) {
$currentSetting = \Civi::settings($domain['id'])->get('editor_id');
if ($currentSetting === 'CKEditor') {
\Civi::setttings($domain['id'])->set('editor_id', 'Textarea');
}
}
civicrm_api3('OptionValue', 'get', ['name' => 'CKEditor', 'api.option_value.delete' => ['id' => "\$value.id"]]);
}

/**
* Example: Run a simple query when a module is enabled.
*/
// public function enable() {
// CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 1 WHERE bar = "whiz"');
// }

/**
* Example: Run a simple query when a module is disabled.
*/
// public function disable() {
// CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 0 WHERE bar = "whiz"');
// }

/**
* Example: Run a couple simple queries.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4200() {
// $this->ctx->log->info('Applying update 4200');
// CRM_Core_DAO::executeQuery('UPDATE foo SET bar = "whiz"');
// CRM_Core_DAO::executeQuery('DELETE FROM bang WHERE willy = wonka(2)');
// return TRUE;
// }


/**
* Example: Run an external SQL script.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4201() {
// $this->ctx->log->info('Applying update 4201');
// // this path is relative to the extension base dir
// $this->executeSqlFile('sql/upgrade_4201.sql');
// return TRUE;
// }


/**
* Example: Run a slow upgrade process by breaking it up into smaller chunk.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4202() {
// $this->ctx->log->info('Planning update 4202'); // PEAR Log interface

// $this->addTask(E::ts('Process first step'), 'processPart1', $arg1, $arg2);
// $this->addTask(E::ts('Process second step'), 'processPart2', $arg3, $arg4);
// $this->addTask(E::ts('Process second step'), 'processPart3', $arg5);
// return TRUE;
// }
// public function processPart1($arg1, $arg2) { sleep(10); return TRUE; }
// public function processPart2($arg3, $arg4) { sleep(10); return TRUE; }
// public function processPart3($arg5) { sleep(10); return TRUE; }

/**
* Example: Run an upgrade with a query that touches many (potentially
* millions) of records by breaking it up into smaller chunks.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4203() {
// $this->ctx->log->info('Planning update 4203'); // PEAR Log interface

// $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contribution');
// $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contribution');
// for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) {
// $endId = $startId + self::BATCH_SIZE - 1;
// $title = E::ts('Upgrade Batch (%1 => %2)', array(
// 1 => $startId,
// 2 => $endId,
// ));
// $sql = '
// UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
// WHERE id BETWEEN %1 and %2
// ';
// $params = array(
// 1 => array($startId, 'Integer'),
// 2 => array($endId, 'Integer'),
// );
// $this->addTask($title, 'executeSql', $sql, $params);
// }
// return TRUE;
// }

}
Loading

0 comments on commit ddca977

Please sign in to comment.