Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
|
@ -8,6 +8,7 @@ drupal.ckeditor:
|
|||
dependencies:
|
||||
- core/jquery
|
||||
- core/drupal
|
||||
- core/drupalSettings
|
||||
- core/drupal.debounce
|
||||
- core/ckeditor
|
||||
- editor/drupal.editor
|
||||
|
@ -22,6 +23,12 @@ drupal.ckeditor.plugins.drupalimagecaption:
|
|||
dependencies:
|
||||
- filter/caption
|
||||
|
||||
drupal.ckeditor.plugins.language:
|
||||
version: VERSION
|
||||
css:
|
||||
component:
|
||||
css/plugins/language/ckeditor.language.css: {}
|
||||
|
||||
drupal.ckeditor.admin:
|
||||
version: VERSION
|
||||
js:
|
||||
|
@ -72,8 +79,16 @@ drupal.ckeditor.stylescombo.admin:
|
|||
dependencies:
|
||||
- core/jquery
|
||||
- core/drupal
|
||||
- core/jquery.once
|
||||
- core/drupal.vertical-tabs
|
||||
- core/drupalSettings
|
||||
# Ensure to run after ckeditor/drupal.ckeditor.admin.
|
||||
- ckeditor/drupal.ckeditor.admin
|
||||
|
||||
drupal.ckeditor.language.admin:
|
||||
version: VERSION
|
||||
js:
|
||||
js/ckeditor.language.admin.js: {}
|
||||
dependencies:
|
||||
- core/jquery
|
||||
- core/drupal
|
||||
- core/drupal.vertical-tabs
|
||||
|
|
|
@ -27,6 +27,8 @@ function ckeditor_help($route_name, RouteMatchInterface $route_match) {
|
|||
$output .= '<dd>' . t('CKEditor only allow users to format content in accordance with the filter configuration of the specific text format. If a text format excludes certain HTML tags, the corresponding toolbar buttons are not displayed to users when they edit a text field in this format. For more information see the <a href=":filter">Filter help page</a>.', array(':filter' => \Drupal::url('help.page', array('name' => 'filter')))) . '</dd>';
|
||||
$output .= '<dt>' . t('Toggling between formatted text and HTML source') . '</dt>';
|
||||
$output .= '<dd>' . t('If the <em>Source</em> button is available in the toolbar, users can click this button to disable the visual editor and edit the HTML source directly. After toggling back, the visual editor uses the allowed HTML tags to format the text — independent of whether buttons for these tags are available in the toolbar. If the text format is set to <em>limit the use of HTML tags</em>, then all excluded tags will be stripped out of the HTML source when the user toggles back to the text editor.') . '</dd>';
|
||||
$output .= '<dt>' . t('Check my spelling as I type') . '</dt>';
|
||||
$output .= '<dd>' . t('By default, CKEditor is configured to leverage your browser\'s spell check capability. Make sure your browser\'s spell checker is enabled in your browser\'s settings. To access suggested corrections for misspelled words, it may be necessary to hold the <em>Control</em> or <em>command</em> (Mac) key while right-clicking the misspelling.') . '</dd>';
|
||||
$output .= '<dt>' . t('Accessibility features') . '</dt>';
|
||||
$output .= '<dd>' . t('The built in WYSIWYG editor (CKEditor) comes with a number of <a href=":features">accessibility features</a>. CKEditor comes with built in <a href=":shortcuts">keyboard shortcuts</a>, which can be beneficial for both power users and keyboard only users.', array(':features' => 'http://docs.ckeditor.com/#!/guide/dev_a11y', ':shortcuts' => 'http://docs.ckeditor.com/#!/guide/dev_shortcuts')) . '</dd>';
|
||||
$output .= '<dt>' . t('Generating accessible content') . '</dt>';
|
||||
|
@ -62,13 +64,6 @@ function ckeditor_ckeditor_css_alter(array &$css, Editor $editor) {
|
|||
if ($editor->getFilterFormat()->filters('filter_caption')->status) {
|
||||
$css[] = drupal_get_path('module', 'filter') . '/css/filter.caption.css';
|
||||
}
|
||||
|
||||
// Add the filter caption CSS if the text format associated with this text
|
||||
// editor uses the filter_align filter. This is used by the included
|
||||
// CKEditor DrupalImageCaption plugin.
|
||||
if ($editor->getFilterFormat()->filters('filter_align')->status) {
|
||||
$css[] = drupal_get_path('module', 'ckeditor') . '/css/plugins/drupalimagecaption/ckeditor.drupalimagecaption.css';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,3 +95,15 @@ function _ckeditor_theme_css($theme = NULL) {
|
|||
}
|
||||
return $css;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_library_info_alter().
|
||||
*/
|
||||
function ckeditor_library_info_alter(&$libraries, $extension) {
|
||||
// Pass Drupal's JS cache-busting string via settings along to CKEditor.
|
||||
// @see http://docs.ckeditor.com/#!/api/CKEDITOR-property-timestamp
|
||||
if ($extension === 'ckeditor' && isset($libraries['drupal.ckeditor'])) {
|
||||
$query_string = \Drupal::state()->get('system.css_js_query_string') ?: '0';
|
||||
$libraries['drupal.ckeditor']['drupalSettings']['ckeditor']['timestamp'] = $query_string;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,15 @@ editor.settings.ckeditor:
|
|||
sequence:
|
||||
type: ckeditor.plugin.[%key]
|
||||
|
||||
# Plugin \Drupal\ckeditor\Plugin\CKEditorPlugin\Language
|
||||
ckeditor.plugin.language:
|
||||
type: mapping
|
||||
label: 'Language'
|
||||
mapping:
|
||||
language_list:
|
||||
type: string
|
||||
label: 'Language list ID'
|
||||
|
||||
# Plugin \Drupal\ckeditor\Plugin\ckeditor\plugin\StylesCombo
|
||||
ckeditor.plugin.stylescombo:
|
||||
type: mapping
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* @file
|
||||
* Language: add styling for elements that have a language attribute.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Show the user that a 'lang' tag has been applied by adding a thin dotted
|
||||
* border. We also append the value of the tag between brackets, for example:
|
||||
* '(en)'. Since the html element has a 'lang' attribute too we only target
|
||||
* elements within the html scope.
|
||||
*/
|
||||
html [lang] {
|
||||
outline: 1px dotted gray;
|
||||
}
|
||||
html [lang]:after {
|
||||
content: " ("attr(lang)")";
|
||||
font-size: 10px;
|
||||
color: #666;
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
* CKEditor button and group configuration user interface.
|
||||
*/
|
||||
|
||||
(function ($, Drupal, _, CKEDITOR) {
|
||||
(function ($, Drupal, drupalSettings, _) {
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -496,4 +496,4 @@
|
|||
return '<li class="ckeditor-add-new-group"><button role="button" aria-label="' + Drupal.t('Add a CKEditor button group to the end of this row.') + '">' + Drupal.t('Add group') + '</button></li>';
|
||||
};
|
||||
|
||||
})(jQuery, Drupal, _, CKEDITOR);
|
||||
})(jQuery, Drupal, drupalSettings, _);
|
||||
|
|
3
core/modules/ckeditor/js/ckeditor.js
vendored
|
@ -273,4 +273,7 @@
|
|||
}
|
||||
});
|
||||
|
||||
// Set the CKEditor cache-busting string to the same value as Drupal.
|
||||
CKEDITOR.timestamp = drupalSettings.ckeditor.timestamp;
|
||||
|
||||
})(Drupal, Drupal.debounce, CKEDITOR, jQuery);
|
||||
|
|
16
core/modules/ckeditor/js/ckeditor.language.admin.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
(function ($, Drupal) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Provides the summary for the "language" plugin settings vertical tab.
|
||||
*/
|
||||
Drupal.behaviors.ckeditorLanguageSettingsSummary = {
|
||||
attach: function () {
|
||||
$('#edit-editor-settings-plugins-language').drupalSetSummary(function (context) {
|
||||
return $('#edit-editor-settings-plugins-language-language-list-type option:selected').text();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery, Drupal);
|
|
@ -3,7 +3,7 @@
|
|||
* CKEditor StylesCombo admin behavior.
|
||||
*/
|
||||
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
(function ($, Drupal, drupalSettings, _) {
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -125,4 +125,4 @@
|
|||
}
|
||||
};
|
||||
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
})(jQuery, Drupal, drupalSettings, _);
|
||||
|
|
Before Width: | Height: | Size: 470 B After Width: | Height: | Size: 470 B |
After Width: | Height: | Size: 1.4 KiB |
|
@ -19,6 +19,8 @@
|
|||
|
||||
CKEDITOR.plugins.add('drupalimage', {
|
||||
requires: 'image2',
|
||||
icons: 'drupalimage',
|
||||
hidpi: true,
|
||||
|
||||
beforeInit: function (editor) {
|
||||
// Override the image2 widget definition to require and handle the
|
||||
|
@ -216,7 +218,7 @@
|
|||
// discovered.
|
||||
// @see plugins/image2/plugin.js/init() in CKEditor; this is similar.
|
||||
if (this.parts.link) {
|
||||
this.setData('link', CKEDITOR.plugins.link.parseLinkAttributes(editor, this.parts.link));
|
||||
this.setData('link', CKEDITOR.plugins.image2.getLinkAttributesParser()(editor, this.parts.link));
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -270,8 +272,7 @@
|
|||
editor.ui.addButton('DrupalImage', {
|
||||
label: Drupal.t('Image'),
|
||||
// Note that we use the original image2 command!
|
||||
command: 'image',
|
||||
icon: this.path + '/image.png'
|
||||
command: 'image'
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -282,6 +283,15 @@
|
|||
|
||||
});
|
||||
|
||||
// Override image2's integration with the official CKEditor link plugin:
|
||||
// integrate with the drupallink plugin instead.
|
||||
CKEDITOR.plugins.image2.getLinkAttributesParser = function () {
|
||||
return CKEDITOR.plugins.drupallink.parseLinkAttributes;
|
||||
};
|
||||
CKEDITOR.plugins.image2.getLinkAttributesGetter = function () {
|
||||
return CKEDITOR.plugins.drupallink.getLinkAttributes;
|
||||
};
|
||||
|
||||
/**
|
||||
* Integrates the drupalimage widget with the drupallink plugin.
|
||||
*
|
||||
|
|
Before Width: | Height: | Size: 328 B After Width: | Height: | Size: 328 B |
Before Width: | Height: | Size: 312 B After Width: | Height: | Size: 312 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.6 KiB |
|
@ -9,7 +9,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
function parseAttributes(element) {
|
||||
function parseAttributes(editor, element) {
|
||||
var parsedAttributes = {};
|
||||
|
||||
var domElement = element.$;
|
||||
|
@ -35,7 +35,36 @@
|
|||
return parsedAttributes;
|
||||
}
|
||||
|
||||
function getAttributes(editor, data) {
|
||||
var set = {};
|
||||
for (var attributeName in data) {
|
||||
if (data.hasOwnProperty(attributeName)) {
|
||||
set[attributeName] = data[attributeName];
|
||||
}
|
||||
}
|
||||
|
||||
// CKEditor tracks the *actual* saved href in a data-cke-saved-* attribute
|
||||
// to work around browser quirks. We need to update it.
|
||||
set['data-cke-saved-href'] = set.href;
|
||||
|
||||
// Remove all attributes which are not currently set.
|
||||
var removed = {};
|
||||
for (var s in set) {
|
||||
if (set.hasOwnProperty(s)) {
|
||||
delete removed[s];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
set: set,
|
||||
removed: CKEDITOR.tools.objectKeys(removed)
|
||||
};
|
||||
}
|
||||
|
||||
CKEDITOR.plugins.add('drupallink', {
|
||||
icons: 'drupallink,drupalunlink',
|
||||
hidpi: true,
|
||||
|
||||
init: function (editor) {
|
||||
// Add the commands for link and unlink.
|
||||
editor.addCommand('drupallink', {
|
||||
|
@ -63,7 +92,7 @@
|
|||
// Set existing values based on selected element.
|
||||
var existingValues = {};
|
||||
if (linkElement && linkElement.$) {
|
||||
existingValues = parseAttributes(linkElement);
|
||||
existingValues = parseAttributes(editor, linkElement);
|
||||
}
|
||||
// Or, if an image widget is focused, we're editing a link wrapping
|
||||
// an image widget.
|
||||
|
@ -169,13 +198,11 @@
|
|||
if (editor.ui.addButton) {
|
||||
editor.ui.addButton('DrupalLink', {
|
||||
label: Drupal.t('Link'),
|
||||
command: 'drupallink',
|
||||
icon: this.path + '/link.png'
|
||||
command: 'drupallink'
|
||||
});
|
||||
editor.ui.addButton('DrupalUnlink', {
|
||||
label: Drupal.t('Unlink'),
|
||||
command: 'drupalunlink',
|
||||
icon: this.path + '/unlink.png'
|
||||
command: 'drupalunlink'
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -266,47 +293,12 @@
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The image2 plugin is currently tightly coupled to the link plugin: it
|
||||
* calls CKEDITOR.plugins.link.parseLinkAttributes().
|
||||
*
|
||||
* Drupal 8's CKEditor build doesn't include the 'link' plugin. Because it
|
||||
* includes its own link plugin that integrates with Drupal's dialog system.
|
||||
* So, to allow images to be linked, we need to duplicate the necessary subset
|
||||
* of the logic.
|
||||
*
|
||||
* @todo Remove once we update to CKEditor 4.5.5.
|
||||
* @see https://dev.ckeditor.com/ticket/13885
|
||||
*/
|
||||
CKEDITOR.plugins.link = CKEDITOR.plugins.link || {
|
||||
parseLinkAttributes: function (editor, element) {
|
||||
return parseAttributes(element);
|
||||
},
|
||||
getLinkAttributes: function (editor, data) {
|
||||
var set = {};
|
||||
for (var attributeName in data) {
|
||||
if (data.hasOwnProperty(attributeName)) {
|
||||
set[attributeName] = data[attributeName];
|
||||
}
|
||||
}
|
||||
|
||||
// CKEditor tracks the *actual* saved href in a data-cke-saved-* attribute
|
||||
// to work around browser quirks. We need to update it.
|
||||
set['data-cke-saved-href'] = set.href;
|
||||
|
||||
// Remove all attributes which are not currently set.
|
||||
var removed = {};
|
||||
for (var s in set) {
|
||||
if (set.hasOwnProperty(s)) {
|
||||
delete removed[s];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
set: set,
|
||||
removed: CKEDITOR.tools.objectKeys(removed)
|
||||
};
|
||||
}
|
||||
// Expose an API for other plugins to interact with drupallink widgets.
|
||||
// (Compatible with the official CKEditor link plugin's API:
|
||||
// http://dev.ckeditor.com/ticket/13885.)
|
||||
CKEDITOR.plugins.drupallink = {
|
||||
parseLinkAttributes: parseAttributes,
|
||||
getLinkAttributes: getAttributes
|
||||
};
|
||||
|
||||
})(jQuery, Drupal, drupalSettings, CKEDITOR);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* A Backbone View acting as a controller for CKEditor toolbar configuration.
|
||||
*/
|
||||
|
||||
(function (Drupal, Backbone, $) {
|
||||
(function ($, Drupal, Backbone, CKEDITOR, _) {
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -380,4 +380,4 @@
|
|||
}
|
||||
});
|
||||
|
||||
})(Drupal, Backbone, jQuery);
|
||||
})(jQuery, Drupal, Backbone, CKEDITOR, _);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Backbone View providing the aural view of CKEditor keyboard UX configuration.
|
||||
*/
|
||||
|
||||
(function (Drupal, Backbone, $) {
|
||||
(function ($, Drupal, Backbone, _) {
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -263,4 +263,4 @@
|
|||
}
|
||||
});
|
||||
|
||||
})(Drupal, Backbone, jQuery);
|
||||
})(jQuery, Drupal, Backbone, _);
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Annotation\CKEditorPlugin.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\CKEditorPluginBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor;
|
||||
|
||||
use Drupal\Core\Plugin\PluginBase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\CKEditorPluginButtonsInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor;
|
||||
|
||||
/**
|
||||
|
@ -23,6 +18,7 @@ namespace Drupal\ckeditor;
|
|||
* @see \Drupal\ckeditor\CKEditorPluginInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginContextualInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginConfigurableInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginCssInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginBase
|
||||
* @see \Drupal\ckeditor\CKEditorPluginManager
|
||||
* @see \Drupal\ckeditor\Annotation\CKEditorPlugin
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\CKEditorPluginConfigurableInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
@ -20,6 +15,7 @@ use Drupal\editor\Entity\Editor;
|
|||
* @see \Drupal\ckeditor\CKEditorPluginInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginButtonsInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginContextualInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginCssInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginBase
|
||||
* @see \Drupal\ckeditor\CKEditorPluginManager
|
||||
* @see \Drupal\ckeditor\Annotation\CKEditorPlugin
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\CKEditorPluginContextualInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor;
|
||||
|
||||
use Drupal\editor\Entity\Editor;
|
||||
|
@ -24,6 +19,7 @@ use Drupal\editor\Entity\Editor;
|
|||
* @see \Drupal\ckeditor\CKEditorPluginInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginButtonsInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginConfigurableInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginCssInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginBase
|
||||
* @see \Drupal\ckeditor\CKEditorPluginManager
|
||||
* @see \Drupal\ckeditor\Annotation\CKEditorPlugin
|
||||
|
|
39
core/modules/ckeditor/src/CKEditorPluginCssInterface.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ckeditor;
|
||||
|
||||
use Drupal\editor\Entity\Editor;
|
||||
|
||||
/**
|
||||
* Defines an interface for CKEditor plugins with associated CSS.
|
||||
*
|
||||
* This allows a CKEditor plugin to add additional CSS in iframe CKEditor
|
||||
* instances without needing to implement hook_ckeditor_css_alter().
|
||||
*
|
||||
* @see \Drupal\ckeditor\CKEditorPluginInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginButtonsInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginContextualInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginConfigurableInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginBase
|
||||
* @see \Drupal\ckeditor\CKEditorPluginManager
|
||||
* @see \Drupal\ckeditor\Annotation\CKEditorPlugin
|
||||
* @see plugin_api
|
||||
*/
|
||||
interface CKEditorPluginCssInterface extends CKEditorPluginInterface {
|
||||
|
||||
/**
|
||||
* Retrieves enabled plugins' iframe instance CSS files.
|
||||
*
|
||||
* Note: this does not use a Drupal asset library because this CSS will be
|
||||
* loaded by CKEditor, not by Drupal.
|
||||
*
|
||||
* @param \Drupal\editor\Entity\Editor $editor
|
||||
* A configured text editor object.
|
||||
*
|
||||
* @return string[]
|
||||
* An array of CSS files. This is a flat list of file paths relative to
|
||||
* the Drupal root.
|
||||
*/
|
||||
public function getCssFiles(Editor $editor);
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\CKEditorPluginInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor;
|
||||
|
||||
use Drupal\Component\Plugin\PluginInspectionInterface;
|
||||
|
@ -28,6 +23,7 @@ use Drupal\editor\Entity\Editor;
|
|||
* @see \Drupal\ckeditor\CKEditorPluginButtonsInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginContextualInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginConfigurableInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginCssInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginBase
|
||||
* @see \Drupal\ckeditor\CKEditorPluginManager
|
||||
* @see \Drupal\ckeditor\Annotation\CKEditorPlugin
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\CKEditorPluginManager.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor;
|
||||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
|
@ -21,6 +16,7 @@ use Drupal\editor\Entity\Editor;
|
|||
* @see \Drupal\ckeditor\CKEditorPluginButtonsInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginContextualInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginConfigurableInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginCssInterface
|
||||
* @see \Drupal\ckeditor\CKEditorPluginBase
|
||||
* @see \Drupal\ckeditor\Annotation\CKEditorPlugin
|
||||
* @see plugin_api
|
||||
|
@ -71,15 +67,7 @@ class CKEditorPluginManager extends DefaultPluginManager {
|
|||
*/
|
||||
public function getEnabledPluginFiles(Editor $editor, $include_internal_plugins = FALSE) {
|
||||
$plugins = array_keys($this->getDefinitions());
|
||||
// Flatten each row.
|
||||
$toolbar_rows = array();
|
||||
$settings = $editor->getSettings();
|
||||
foreach ($settings['toolbar']['rows'] as $row_number => $row) {
|
||||
$toolbar_rows[] = array_reduce($settings['toolbar']['rows'][$row_number], function (&$result, $button_group) {
|
||||
return array_merge($result, $button_group['items']);
|
||||
}, array());
|
||||
}
|
||||
$toolbar_buttons = array_unique(NestedArray::mergeDeepArray($toolbar_rows));
|
||||
$toolbar_buttons = $this->getEnabledButtons($editor);
|
||||
$enabled_plugins = array();
|
||||
$additional_plugins = array();
|
||||
|
||||
|
@ -120,6 +108,26 @@ class CKEditorPluginManager extends DefaultPluginManager {
|
|||
return $enabled_plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the enabled toolbar buttons in the given text editor instance.
|
||||
*
|
||||
* @param \Drupal\editor\Entity\Editor $editor
|
||||
* A configured text editor object.
|
||||
*
|
||||
* @return string[]
|
||||
* A list of the toolbar buttons enabled in the given text editor instance.
|
||||
*/
|
||||
public static function getEnabledButtons(Editor $editor) {
|
||||
$toolbar_rows = [];
|
||||
$settings = $editor->getSettings();
|
||||
foreach ($settings['toolbar']['rows'] as $row_number => $row) {
|
||||
$toolbar_rows[] = array_reduce($settings['toolbar']['rows'][$row_number], function (&$result, $button_group) {
|
||||
return array_merge($result, $button_group['items']);
|
||||
}, []);
|
||||
}
|
||||
return array_unique(NestedArray::mergeDeepArray($toolbar_rows));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all available CKEditor buttons, keyed by plugin ID.
|
||||
*
|
||||
|
@ -127,7 +135,7 @@ class CKEditorPluginManager extends DefaultPluginManager {
|
|||
* All available CKEditor buttons, with plugin IDs as keys and button
|
||||
* metadata (as implemented by getButtons()) as values.
|
||||
*
|
||||
* @see CKEditorPluginButtonsInterface::getButtons()
|
||||
* @see \Drupal\ckeditor\CKEditorPluginButtonsInterface::getButtons()
|
||||
*/
|
||||
public function getButtons() {
|
||||
$plugins = array_keys($this->getDefinitions());
|
||||
|
@ -182,4 +190,32 @@ class CKEditorPluginManager extends DefaultPluginManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves enabled plugins' iframe instance CSS files, keyed by plugin ID.
|
||||
*
|
||||
* @param \Drupal\editor\Entity\Editor $editor
|
||||
* A configured text editor object.
|
||||
*
|
||||
* @return string[]
|
||||
* Enabled plugins CKEditor CSS files, with plugin IDs as keys and CSS file
|
||||
* paths relative to the Drupal root (as implemented by getCssFiles()) as
|
||||
* values.
|
||||
*
|
||||
* @see \Drupal\ckeditor\CKEditorPluginCssInterface::getCssFiles()
|
||||
*/
|
||||
public function getCssFiles(Editor $editor) {
|
||||
$enabled_plugins = array_keys($this->getEnabledPluginFiles($editor, TRUE));
|
||||
$css_files = array();
|
||||
|
||||
foreach ($enabled_plugins as $plugin_id) {
|
||||
$plugin = $this->createInstance($plugin_id);
|
||||
if ($plugin instanceof CKEditorPluginCssInterface) {
|
||||
$css_files[$plugin_id] = $plugin->getCssFiles($editor);
|
||||
}
|
||||
}
|
||||
|
||||
return $css_files;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalImage.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\ckeditor\CKEditorPluginBase;
|
||||
|
@ -56,7 +51,7 @@ class DrupalImage extends CKEditorPluginBase implements CKEditorPluginConfigurab
|
|||
return array(
|
||||
'DrupalImage' => array(
|
||||
'label' => t('Image'),
|
||||
'image' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/image.png',
|
||||
'image' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/icons/drupalimage.png',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalImageCaption.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\Component\Plugin\PluginBase;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Drupal\ckeditor\CKEditorPluginInterface;
|
||||
use Drupal\ckeditor\CKEditorPluginContextualInterface;
|
||||
use Drupal\ckeditor\CKEditorPluginCssInterface;
|
||||
|
||||
/**
|
||||
* Defines the "drupalimagecaption" plugin.
|
||||
|
@ -21,7 +17,7 @@ use Drupal\ckeditor\CKEditorPluginContextualInterface;
|
|||
* module = "ckeditor"
|
||||
* )
|
||||
*/
|
||||
class DrupalImageCaption extends PluginBase implements CKEditorPluginInterface, CKEditorPluginContextualInterface {
|
||||
class DrupalImageCaption extends PluginBase implements CKEditorPluginInterface, CKEditorPluginContextualInterface, CKEditorPluginCssInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -69,6 +65,15 @@ class DrupalImageCaption extends PluginBase implements CKEditorPluginInterface,
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCssFiles(Editor $editor) {
|
||||
return array(
|
||||
drupal_get_path('module', 'ckeditor') . '/css/plugins/drupalimagecaption/ckeditor.drupalimagecaption.css'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalLink.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\ckeditor\CKEditorPluginBase;
|
||||
|
@ -55,11 +50,11 @@ class DrupalLink extends CKEditorPluginBase {
|
|||
return array(
|
||||
'DrupalLink' => array(
|
||||
'label' => t('Link'),
|
||||
'image' => $path . '/link.png',
|
||||
'image' => $path . '/icons/drupallink.png',
|
||||
),
|
||||
'DrupalUnlink' => array(
|
||||
'label' => t('Unlink'),
|
||||
'image' => $path . '/unlink.png',
|
||||
'image' => $path . '/icons/drupalunlink.png',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\ckeditor\CKEditorPluginBase;
|
||||
use Drupal\ckeditor\CKEditorPluginContextualInterface;
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
|
@ -24,7 +20,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
* label = @Translation("CKEditor core")
|
||||
* )
|
||||
*/
|
||||
class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInterface {
|
||||
class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInterface, CKEditorPluginContextualInterface {
|
||||
|
||||
/**
|
||||
* The cache backend.
|
||||
|
@ -81,6 +77,15 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isEnabled(Editor $editor) {
|
||||
// This plugin represents the core CKEditor plugins. They're always enabled:
|
||||
// its configuration is always necessary.
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -100,6 +105,7 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
|
|||
'resize_dir' => 'vertical',
|
||||
'justifyClasses' => array('text-align-left', 'text-align-center', 'text-align-right', 'text-align-justify'),
|
||||
'entities' => FALSE,
|
||||
'disableNativeSpellChecker' => FALSE,
|
||||
);
|
||||
|
||||
// Add the allowedContent setting, which ensures CKEditor only allows tags
|
||||
|
|
136
core/modules/ckeditor/src/Plugin/CKEditorPlugin/Language.php
Normal file
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ckeditor\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\ckeditor\CKEditorPluginBase;
|
||||
use Drupal\ckeditor\CKEditorPluginConfigurableInterface;
|
||||
use Drupal\ckeditor\CKEditorPluginCssInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageManager;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
|
||||
/**
|
||||
* Defines the "language" plugin.
|
||||
*
|
||||
* @CKEditorPlugin(
|
||||
* id = "language",
|
||||
* label = @Translation("Language")
|
||||
* )
|
||||
*/
|
||||
class Language extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface, CKEditorPluginCssInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isInternal() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFile() {
|
||||
// This plugin is already part of Drupal core's CKEditor build.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLibraries(Editor $editor) {
|
||||
return ['ckeditor/drupal.ckeditor.plugins.language'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfig(Editor $editor) {
|
||||
$language_list = [];
|
||||
$config = ['language_list' => 'un'];
|
||||
$settings = $editor->getSettings();
|
||||
if (isset($settings['plugins']['language'])) {
|
||||
$config = $settings['plugins']['language'];
|
||||
}
|
||||
|
||||
$predefined_languages = ($config['language_list'] === 'all') ?
|
||||
LanguageManager::getStandardLanguageList() :
|
||||
LanguageManager::getUnitedNationsLanguageList();
|
||||
|
||||
// Generate the language_list setting as expected by the CKEditor Language
|
||||
// plugin, but key the values by the full language name so that we can sort
|
||||
// them later on.
|
||||
foreach ($predefined_languages as $langcode => $language) {
|
||||
$english_name = $language[0];
|
||||
$direction = empty($language[2]) ? NULL : $language[2];
|
||||
if ($direction === LanguageInterface::DIRECTION_RTL) {
|
||||
$language_list[$english_name] = $langcode . ':' . $english_name . ':rtl';
|
||||
}
|
||||
else {
|
||||
$language_list[$english_name] = $langcode . ':' . $english_name;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort on full language name.
|
||||
ksort($language_list);
|
||||
$config = ['language_list' => array_values($language_list)];
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getButtons() {
|
||||
return [
|
||||
'Language' => [
|
||||
'label' => $this->t('Language'),
|
||||
'image_alternative' => [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => '<a href="#" class="cke-icon-only" role="button" title="' . $this->t('Language') . '" aria-label="' . $this->t('Language') . '"><span class="cke_button_icon cke_button__language_icon">' . $this->t('Language') . '</span></a>',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
|
||||
// Defaults.
|
||||
$config = ['language_list' => 'un'];
|
||||
$settings = $editor->getSettings();
|
||||
if (isset($settings['plugins']['language'])) {
|
||||
$config = $settings['plugins']['language'];
|
||||
}
|
||||
|
||||
$predefined_languages = LanguageManager::getStandardLanguageList();
|
||||
$form['language_list'] = array(
|
||||
'#title' => $this->t('Language list'),
|
||||
'#title_display' => 'invisible',
|
||||
'#type' => 'select',
|
||||
'#options' => [
|
||||
'un' => $this->t("United Nations' official languages"),
|
||||
'all' => $this->t('All @count languages', ['@count' => count($predefined_languages)]),
|
||||
],
|
||||
'#default_value' => $config['language_list'],
|
||||
'#description' => $this->t('The list of languages to show in the language dropdown. The basic list will only show the <a href=":url">six official languages of the UN</a>. The extended list will show all @count languages that are available in Drupal.', [
|
||||
':url' => Url::fromUri('http://www.un.org/en/aboutun/languages.shtml/')->toString(),
|
||||
'@count' => count($predefined_languages),
|
||||
]),
|
||||
'#attached' => ['library' => ['ckeditor/drupal.ckeditor.language.admin']],
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function getCssFiles(Editor $editor) {
|
||||
return array(
|
||||
drupal_get_path('module', 'ckeditor') . '/css/plugins/language/ckeditor.language.css'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Plugin\CKEditorPlugin\StylesCombo.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\ckeditor\CKEditorPluginBase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Plugin\Editor\CKEditor.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor\Plugin\Editor;
|
||||
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
|
@ -15,7 +10,7 @@ use Drupal\Core\Render\Element;
|
|||
use Drupal\Core\Render\RendererInterface;
|
||||
use Drupal\editor\Plugin\EditorBase;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\editor\Entity\Editor as EditorEntity;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -135,14 +130,14 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
|
|||
),
|
||||
),
|
||||
),
|
||||
'plugins' => array(),
|
||||
'plugins' => ['language' => ['language_list' => 'un']],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsForm(array $form, FormStateInterface $form_state, EditorEntity $editor) {
|
||||
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
|
||||
$settings = $editor->getSettings();
|
||||
|
||||
$ckeditor_settings_toolbar = array(
|
||||
|
@ -204,7 +199,7 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
|
|||
}, array());
|
||||
// Build a fake Editor object, which we'll use to generate JavaScript
|
||||
// settings for this fake Editor instance.
|
||||
$fake_editor = entity_create('editor', array(
|
||||
$fake_editor = Editor::create(array(
|
||||
'format' => $editor->id(),
|
||||
'editor' => 'ckeditor',
|
||||
'settings' => array(
|
||||
|
@ -259,7 +254,7 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getJSSettings(EditorEntity $editor) {
|
||||
public function getJSSettings(Editor $editor) {
|
||||
$settings = array();
|
||||
|
||||
// Get the settings for all enabled plugins, even the internal ones.
|
||||
|
@ -367,7 +362,7 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLibraries(EditorEntity $editor) {
|
||||
public function getLibraries(Editor $editor) {
|
||||
$libraries = array(
|
||||
'ckeditor/drupal.ckeditor',
|
||||
);
|
||||
|
@ -393,7 +388,7 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
|
|||
* @return array
|
||||
* An array containing the "toolbar" configuration.
|
||||
*/
|
||||
public function buildToolbarJSSetting(EditorEntity $editor) {
|
||||
public function buildToolbarJSSetting(Editor $editor) {
|
||||
$toolbar = array();
|
||||
|
||||
$settings = $editor->getSettings();
|
||||
|
@ -416,12 +411,17 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
|
|||
* @return array
|
||||
* An array containing the "contentsCss" configuration.
|
||||
*/
|
||||
public function buildContentsCssJSSetting(EditorEntity $editor) {
|
||||
public function buildContentsCssJSSetting(Editor $editor) {
|
||||
$css = array(
|
||||
drupal_get_path('module', 'ckeditor') . '/css/ckeditor-iframe.css',
|
||||
drupal_get_path('module', 'system') . '/css/components/align.module.css',
|
||||
);
|
||||
$this->moduleHandler->alter('ckeditor_css', $css, $editor);
|
||||
// Get a list of all enabled plugins' iframe instance CSS files.
|
||||
$plugins_css = array_reduce($this->ckeditorPluginManager->getCssFiles($editor), function($result, $item) {
|
||||
return array_merge($result, array_values($item));
|
||||
}, array());
|
||||
$css = array_merge($css, $plugins_css);
|
||||
$css = array_merge($css, _ckeditor_theme_css());
|
||||
$css = array_map('file_create_url', $css);
|
||||
$css = array_map('file_url_transform_relative', $css);
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Tests\CKEditorAdminTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor\Tests;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Drupal\filter\FilterFormatInterface;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
/**
|
||||
* Tests administration of CKEditor.
|
||||
|
@ -37,7 +33,7 @@ class CKEditorAdminTest extends WebTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create text format.
|
||||
$filtered_html_format = entity_create('filter_format', array(
|
||||
$filtered_html_format = FilterFormat::create(array(
|
||||
'format' => 'filtered_html',
|
||||
'name' => 'Filtered HTML',
|
||||
'weight' => 0,
|
||||
|
@ -109,7 +105,7 @@ class CKEditorAdminTest extends WebTestBase {
|
|||
),
|
||||
),
|
||||
),
|
||||
'plugins' => array(),
|
||||
'plugins' => ['language' => ['language_list' => 'un']],
|
||||
);
|
||||
$this->assertIdentical($this->castSafeStrings($ckeditor->getDefaultSettings()), $expected_default_settings);
|
||||
|
||||
|
@ -148,7 +144,7 @@ class CKEditorAdminTest extends WebTestBase {
|
|||
$expected_settings['plugins']['stylescombo']['styles'] = '';
|
||||
$editor = entity_load('editor', 'filtered_html');
|
||||
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists now.');
|
||||
$this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
|
||||
$this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
|
||||
|
||||
// Configure the Styles plugin, and ensure the updated settings are saved.
|
||||
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
|
||||
|
@ -159,7 +155,7 @@ class CKEditorAdminTest extends WebTestBase {
|
|||
$expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
|
||||
$editor = entity_load('editor', 'filtered_html');
|
||||
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
|
||||
$this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
|
||||
$this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
|
||||
|
||||
// Change the buttons that appear on the toolbar (in JavaScript, this is
|
||||
// done via drag and drop, but here we can only emulate the end result of
|
||||
|
@ -175,7 +171,7 @@ class CKEditorAdminTest extends WebTestBase {
|
|||
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
|
||||
$editor = entity_load('editor', 'filtered_html');
|
||||
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
|
||||
$this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
|
||||
$this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
|
||||
|
||||
// Check that the markup we're setting for the toolbar buttons (actually in
|
||||
// JavaScript's drupalSettings, and Unicode-escaped) is correctly rendered.
|
||||
|
@ -203,7 +199,7 @@ class CKEditorAdminTest extends WebTestBase {
|
|||
$this->assertTrue(count($ultra_llama_mode_checkbox) === 1, 'The "Ultra llama mode" checkbox exists and is not checked.');
|
||||
$editor = entity_load('editor', 'filtered_html');
|
||||
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
|
||||
$this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
|
||||
$this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
|
||||
|
||||
// Finally, check the "Ultra llama mode" checkbox.
|
||||
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
|
||||
|
@ -217,7 +213,7 @@ class CKEditorAdminTest extends WebTestBase {
|
|||
$expected_settings['plugins']['llama_contextual_and_button']['ultra_llama_mode'] = TRUE;
|
||||
$editor = entity_load('editor', 'filtered_html');
|
||||
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
|
||||
$this->assertIdentical($expected_settings, $editor->getSettings());
|
||||
$this->assertEqual($expected_settings, $editor->getSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -282,7 +278,7 @@ class CKEditorAdminTest extends WebTestBase {
|
|||
$expected_settings['plugins']['stylescombo']['styles'] = '';
|
||||
$editor = entity_load('editor', 'amazing_format');
|
||||
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists now.');
|
||||
$this->assertIdentical($this->castSafeStrings($expected_settings), $this->castSafeStrings($editor->getSettings()), 'The Editor config entity has the correct settings.');
|
||||
$this->assertEqual($this->castSafeStrings($expected_settings), $this->castSafeStrings($editor->getSettings()), 'The Editor config entity has the correct settings.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Tests\CKEditorLoadingTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor\Tests;
|
||||
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
/**
|
||||
* Tests loading of CKEditor.
|
||||
|
@ -41,22 +38,22 @@ class CKEditorLoadingTest extends WebTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create text format, associate CKEditor.
|
||||
$filtered_html_format = entity_create('filter_format', array(
|
||||
$filtered_html_format = FilterFormat::create(array(
|
||||
'format' => 'filtered_html',
|
||||
'name' => 'Filtered HTML',
|
||||
'weight' => 0,
|
||||
'filters' => array(),
|
||||
));
|
||||
$filtered_html_format->save();
|
||||
$editor = entity_create('editor', array(
|
||||
$editor = Editor::create([
|
||||
'format' => 'filtered_html',
|
||||
'editor' => 'ckeditor',
|
||||
));
|
||||
]);
|
||||
$editor->save();
|
||||
|
||||
// Create a second format without an associated editor so a drop down select
|
||||
// list is created when selecting formats.
|
||||
$full_html_format = entity_create('filter_format', array(
|
||||
$full_html_format = FilterFormat::create(array(
|
||||
'format' => 'full_html',
|
||||
'name' => 'Full HTML',
|
||||
'weight' => 1,
|
||||
|
@ -146,6 +143,55 @@ class CKEditorLoadingTest extends WebTestBase {
|
|||
$this->assertIdentical($expected, $this->castSafeStrings($settings['editor']), "Text Editor module's JavaScript settings on the page are correct.");
|
||||
$this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.');
|
||||
$this->assertTrue(in_array('ckeditor/drupal.ckeditor', explode(',', $settings['ajaxPageState']['libraries'])), 'CKEditor glue library is present.');
|
||||
|
||||
// Assert that CKEditor uses Drupal's cache-busting query string by
|
||||
// comparing the setting sent with the page with the current query string.
|
||||
$settings = $this->getDrupalSettings();
|
||||
$expected = $settings['ckeditor']['timestamp'];
|
||||
$this->assertIdentical($expected, \Drupal::state()->get('system.css_js_query_string'), "CKEditor scripts cache-busting string is correct before flushing all caches.");
|
||||
// Flush all caches then make sure that $settings['ckeditor']['timestamp']
|
||||
// still matches.
|
||||
drupal_flush_all_caches();
|
||||
$this->assertIdentical($expected, \Drupal::state()->get('system.css_js_query_string'), "CKEditor scripts cache-busting string is correct after flushing all caches.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests presence of essential configuration even without Internal's buttons.
|
||||
*/
|
||||
protected function testLoadingWithoutInternalButtons() {
|
||||
// Change the CKEditor text editor configuration to only have link buttons.
|
||||
// This means:
|
||||
// - 0 buttons are from \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal
|
||||
// - 2 buttons are from \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalLink
|
||||
$filtered_html_editor = Editor::load('filtered_html');
|
||||
$settings = $filtered_html_editor->getSettings();
|
||||
$settings['toolbar']['rows'] = [
|
||||
0 => [
|
||||
0 => [
|
||||
'name' => 'Links',
|
||||
'items' => [
|
||||
'DrupalLink',
|
||||
'DrupalUnlink',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$filtered_html_editor->setSettings($settings)->save();
|
||||
|
||||
// Even when no buttons of \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal
|
||||
// are in use, its configuration (Internal::getConfig()) is still essential:
|
||||
// this is configuration that is associated with the (custom, optimized)
|
||||
// build of CKEditor that Drupal core ships with. For example, it configures
|
||||
// CKEditor to not perform its default action of loading a config.js file,
|
||||
// to not convert special characters into HTML entities, and the allowedContent
|
||||
// setting to configure CKEditor's Advanced Content Filter.
|
||||
$this->drupalLogin($this->normalUser);
|
||||
$this->drupalGet('node/add/article');
|
||||
$editor_settings = $this->getDrupalSettings()['editor']['formats']['filtered_html']['editorSettings'];
|
||||
$this->assertTrue(isset($editor_settings['customConfig']));
|
||||
$this->assertTrue(isset($editor_settings['entities']));
|
||||
$this->assertTrue(isset($editor_settings['allowedContent']));
|
||||
$this->assertTrue(isset($editor_settings['disallowedContent']));
|
||||
}
|
||||
|
||||
protected function getThingsToCheck() {
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Tests\CKEditorToolbarButtonTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor\Tests;
|
||||
|
||||
|
@ -74,7 +70,7 @@ class CKEditorToolbarButtonTest extends WebTestBase {
|
|||
$json_encode = function($html) {
|
||||
return trim(Json::encode($html), '"');
|
||||
};
|
||||
$markup = $json_encode(file_url_transform_relative(file_create_url('core/modules/ckeditor/js/plugins/drupalimage/image.png')));
|
||||
$markup = $json_encode(file_url_transform_relative(file_create_url('core/modules/ckeditor/js/plugins/drupalimage/icons/drupalimage.png')));
|
||||
$this->assertRaw($markup);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Tests\CKEditorPluginManagerTest.
|
||||
*/
|
||||
namespace Drupal\Tests\ckeditor\Kernel;
|
||||
|
||||
namespace Drupal\ckeditor\Tests;
|
||||
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
/**
|
||||
* Tests different ways of enabling CKEditor plugins.
|
||||
|
@ -34,20 +31,19 @@ class CKEditorPluginManagerTest extends KernelTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Install the Filter module.
|
||||
$this->installSchema('system', 'url_alias');
|
||||
|
||||
// Create text format, associate CKEditor.
|
||||
$filtered_html_format = entity_create('filter_format', array(
|
||||
$filtered_html_format = FilterFormat::create(array(
|
||||
'format' => 'filtered_html',
|
||||
'name' => 'Filtered HTML',
|
||||
'weight' => 0,
|
||||
'filters' => array(),
|
||||
));
|
||||
$filtered_html_format->save();
|
||||
$editor = entity_create('editor', array(
|
||||
$editor = Editor::create([
|
||||
'format' => 'filtered_html',
|
||||
'editor' => 'ckeditor',
|
||||
));
|
||||
]);
|
||||
$editor->save();
|
||||
}
|
||||
|
||||
|
@ -56,20 +52,20 @@ class CKEditorPluginManagerTest extends KernelTestBase {
|
|||
*/
|
||||
function testEnabledPlugins() {
|
||||
$this->manager = $this->container->get('plugin.manager.ckeditor.plugin');
|
||||
$editor = entity_load('editor', 'filtered_html');
|
||||
$editor = Editor::load('filtered_html');
|
||||
|
||||
// Case 1: no CKEditor plugins.
|
||||
$definitions = array_keys($this->manager->getDefinitions());
|
||||
sort($definitions);
|
||||
$this->assertIdentical(array('drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'stylescombo'), $definitions, 'No CKEditor plugins found besides the built-in ones.');
|
||||
$this->assertIdentical(array('drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'stylescombo'), $definitions, 'No CKEditor plugins found besides the built-in ones.');
|
||||
$enabled_plugins = array(
|
||||
'drupalimage' => 'core/modules/ckeditor/js/plugins/drupalimage/plugin.js',
|
||||
'drupallink' => 'core/modules/ckeditor/js/plugins/drupallink/plugin.js',
|
||||
'drupalimage' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/plugin.js',
|
||||
'drupallink' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupallink/plugin.js',
|
||||
);
|
||||
$this->assertIdentical($enabled_plugins, $this->manager->getEnabledPluginFiles($editor), 'Only built-in plugins are enabled.');
|
||||
$this->assertIdentical(array('internal' => NULL) + $enabled_plugins, $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.');
|
||||
|
||||
// Enable the CKEditor Test module, which has the Llama plugin (plus three
|
||||
// Enable the CKEditor Test module, which has the Llama plugin (plus four
|
||||
// variations of it, to cover all possible ways a plugin can be enabled) and
|
||||
// clear the editor manager's cache so it is picked up.
|
||||
$this->enableModules(array('ckeditor_test'));
|
||||
|
@ -79,7 +75,7 @@ class CKEditorPluginManagerTest extends KernelTestBase {
|
|||
// Case 2: CKEditor plugins are available.
|
||||
$plugin_ids = array_keys($this->manager->getDefinitions());
|
||||
sort($plugin_ids);
|
||||
$this->assertIdentical(array('drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'llama', 'llama_button', 'llama_contextual', 'llama_contextual_and_button', 'stylescombo'), $plugin_ids, 'Additional CKEditor plugins found.');
|
||||
$this->assertIdentical(array('drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'llama', 'llama_button', 'llama_contextual', 'llama_contextual_and_button', 'llama_css', 'stylescombo'), $plugin_ids, 'Additional CKEditor plugins found.');
|
||||
$this->assertIdentical($enabled_plugins, $this->manager->getEnabledPluginFiles($editor), 'Only the internal plugins are enabled.');
|
||||
$this->assertIdentical(array('internal' => NULL) + $enabled_plugins, $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.');
|
||||
|
||||
|
@ -90,21 +86,25 @@ class CKEditorPluginManagerTest extends KernelTestBase {
|
|||
// part of another plugin!
|
||||
// c. LlamaButton: automatically enabled by adding its 'Llama' button.
|
||||
// d. LlamaContextualAndButton: enabled by either b or c.
|
||||
// e. LlamaCSS: automatically enabled by add its 'LlamaCSS' button.
|
||||
// Below, we will first enable the "Llama" button, which will cause the
|
||||
// LlamaButton and LlamaContextualAndButton plugins to be enabled. Then we
|
||||
// will remove the "Llama" button and add the "Strike" button, which will
|
||||
// cause the LlamaContextual and LlamaContextualAndButton plugins to be
|
||||
// enabled. Finally, we will add the "Strike" button back again, which would
|
||||
// cause all three plugins to be enabled.
|
||||
// enabled. Then we will add the "Strike" button back again, which would
|
||||
// cause LlamaButton, LlamaContextual and LlamaContextualAndButton to be
|
||||
// enabled. Finally, we will add the "LlamaCSS" button which would cause
|
||||
// all four plugins to be enabled.
|
||||
$settings = $editor->getSettings();
|
||||
$original_toolbar = $settings['toolbar'];
|
||||
$settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
|
||||
$editor->setSettings($settings);
|
||||
$editor->save();
|
||||
$file = array();
|
||||
$file['b'] = 'core/modules/ckeditor/tests/modules/js/llama_button.js';
|
||||
$file['c'] = 'core/modules/ckeditor/tests/modules/js/llama_contextual.js';
|
||||
$file['cb'] = 'core/modules/ckeditor/tests/modules/js/llama_contextual_and_button.js';
|
||||
$file['b'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_button.js';
|
||||
$file['c'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual.js';
|
||||
$file['cb'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual_and_button.js';
|
||||
$file['css'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_css.js';
|
||||
$expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual_and_button' => $file['cb']);
|
||||
$this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.');
|
||||
$this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.');
|
||||
|
@ -121,6 +121,39 @@ class CKEditorPluginManagerTest extends KernelTestBase {
|
|||
$expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']);
|
||||
$this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.');
|
||||
$this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.');
|
||||
$settings['toolbar']['rows'][0][0]['items'][] = 'LlamaCSS';
|
||||
$editor->setSettings($settings);
|
||||
$editor->save();
|
||||
$expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb'], 'llama_css' => $file['css']);
|
||||
$this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton, LlamaContextual, LlamaContextualAndButton and LlamaCSS plugins are enabled.');
|
||||
$this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual, LlamaContextualAndButton and LlamaCSS plugins are enabled.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the iframe instance CSS files of plugins.
|
||||
*/
|
||||
function testCssFiles() {
|
||||
$this->manager = $this->container->get('plugin.manager.ckeditor.plugin');
|
||||
$editor = Editor::load('filtered_html');
|
||||
|
||||
// Case 1: no CKEditor iframe instance CSS file.
|
||||
$this->assertIdentical(array(), $this->manager->getCssFiles($editor), 'No iframe instance CSS file found.');
|
||||
|
||||
// Enable the CKEditor Test module, which has the LlamaCss plugin and
|
||||
// clear the editor manager's cache so it is picked up.
|
||||
$this->enableModules(array('ckeditor_test'));
|
||||
$this->manager = $this->container->get('plugin.manager.ckeditor.plugin');
|
||||
$settings = $editor->getSettings();
|
||||
// LlamaCss: automatically enabled by adding its 'LlamaCSS' button.
|
||||
$settings['toolbar']['rows'][0][0]['items'][] = 'LlamaCSS';
|
||||
$editor->setSettings($settings);
|
||||
$editor->save();
|
||||
|
||||
// Case 2: CKEditor iframe instance CSS file.
|
||||
$expected = array(
|
||||
'llama_css' => array(drupal_get_path('module', 'ckeditor_test') . '/css/llama.css')
|
||||
);
|
||||
$this->assertIdentical($expected, $this->manager->getCssFiles($editor), 'Iframe instance CSS file found.');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor\Tests\CKEditorTest.
|
||||
*/
|
||||
namespace Drupal\Tests\ckeditor\Kernel;
|
||||
|
||||
namespace Drupal\ckeditor\Tests;
|
||||
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
/**
|
||||
* Tests for the 'CKEditor' text editor plugin.
|
||||
|
@ -43,10 +39,9 @@ class CKEditorTest extends KernelTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Install the Filter module.
|
||||
$this->installSchema('system', 'url_alias');
|
||||
|
||||
// Create text format, associate CKEditor.
|
||||
$filtered_html_format = entity_create('filter_format', array(
|
||||
$filtered_html_format = FilterFormat::create(array(
|
||||
'format' => 'filtered_html',
|
||||
'name' => 'Filtered HTML',
|
||||
'weight' => 0,
|
||||
|
@ -60,10 +55,10 @@ class CKEditorTest extends KernelTestBase {
|
|||
),
|
||||
));
|
||||
$filtered_html_format->save();
|
||||
$editor = entity_create('editor', array(
|
||||
$editor = Editor::create([
|
||||
'format' => 'filtered_html',
|
||||
'editor' => 'ckeditor',
|
||||
));
|
||||
]);
|
||||
$editor->save();
|
||||
|
||||
// Create "CKEditor" text editor plugin instance.
|
||||
|
@ -261,12 +256,24 @@ class CKEditorTest extends KernelTestBase {
|
|||
|
||||
// Enable the editor_test module, which implements hook_ckeditor_css_alter().
|
||||
$this->enableModules(array('ckeditor_test'));
|
||||
$expected[] = file_url_transform_relative(file_create_url('core/modules/ckeditor/tests/modules/ckeditor_test.css'));
|
||||
$expected[] = file_url_transform_relative(file_create_url(drupal_get_path('module', 'ckeditor_test') . '/ckeditor_test.css'));
|
||||
$this->assertIdentical($expected, $this->ckeditor->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly while a hook_ckeditor_css_alter() implementation exists.');
|
||||
|
||||
// Enable LlamaCss plugin, which adds an additional CKEditor stylesheet.
|
||||
$this->container->get('plugin.manager.editor')->clearCachedDefinitions();
|
||||
$this->ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
|
||||
$this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions();
|
||||
$settings = $editor->getSettings();
|
||||
// LlamaCss: automatically enabled by adding its 'LlamaCSS' button.
|
||||
$settings['toolbar']['rows'][0][0]['items'][] = 'LlamaCSS';
|
||||
$editor->setSettings($settings);
|
||||
$editor->save();
|
||||
$expected[] = file_url_transform_relative(file_create_url(drupal_get_path('module', 'ckeditor_test') . '/css/llama.css'));
|
||||
$this->assertIdentical($expected, $this->ckeditor->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly while a CKEditorPluginInterface implementation exists.');
|
||||
|
||||
// Enable the Bartik theme, which specifies a CKEditor stylesheet.
|
||||
\Drupal::service('theme_handler')->install(['bartik']);
|
||||
$this->config('system.theme')->set('default', 'bartik')->save();
|
||||
\Drupal::service('theme_handler')->setDefault('bartik');
|
||||
$expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/base/elements.css'));
|
||||
$expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/components/captions.css'));
|
||||
$expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/components/table.css'));
|
||||
|
@ -427,6 +434,7 @@ class CKEditorTest extends KernelTestBase {
|
|||
'resize_dir' => 'vertical',
|
||||
'justifyClasses' => array('text-align-left', 'text-align-center', 'text-align-right', 'text-align-justify'),
|
||||
'entities' => FALSE,
|
||||
'disableNativeSpellChecker' => FALSE,
|
||||
);
|
||||
}
|
||||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor_test\Plugin\CKEditorPlugin\Llama.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor_test\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\ckeditor\CKEditorPluginInterface;
|
||||
|
@ -19,9 +14,10 @@ use Drupal\editor\Entity\Editor;
|
|||
* CKEditorPluginButtonsInterface interface, there is no way of actually loading
|
||||
* this plugin.
|
||||
*
|
||||
* @see MetaContextual
|
||||
* @see MetaButton
|
||||
* @see MetaContextualAndButton
|
||||
* @see \Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaContextual
|
||||
* @see \Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaButton
|
||||
* @see \Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaContextualAndButton
|
||||
* @see \Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaCss
|
||||
*
|
||||
* @CKEditorPlugin(
|
||||
* id = "llama",
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaButton.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor_test\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\ckeditor\CKEditorPluginButtonsInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaContextual.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor_test\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\ckeditor\CKEditorPluginContextualInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaContextualAndButton.
|
||||
*/
|
||||
|
||||
namespace Drupal\ckeditor_test\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\ckeditor\CKEditorPluginButtonsInterface;
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ckeditor_test\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\ckeditor\CKEditorPluginButtonsInterface;
|
||||
use Drupal\ckeditor\CKEditorPluginCssInterface;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
|
||||
/**
|
||||
* Defines a "LlamaCss" plugin, with an associated "llama" CSS.
|
||||
*
|
||||
* @CKEditorPlugin(
|
||||
* id = "llama_css",
|
||||
* label = @Translation("Llama CSS")
|
||||
* )
|
||||
*/
|
||||
class LlamaCss extends Llama implements CKEditorPluginButtonsInterface, CKEditorPluginCssInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function getButtons() {
|
||||
return array(
|
||||
'LlamaCSS' => array(
|
||||
'label' => t('Insert Llama CSS'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function getCssFiles(Editor $editor) {
|
||||
return array(
|
||||
drupal_get_path('module', 'ckeditor_test') . '/css/llama.css'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function getFile() {
|
||||
return drupal_get_path('module', 'ckeditor_test') . '/js/llama_css.js';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\ckeditor\Unit;
|
||||
|
||||
use Drupal\ckeditor\CKEditorPluginManager;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\ckeditor\CKEditorPluginManager
|
||||
*
|
||||
* @group ckeditor
|
||||
*/
|
||||
class CKEditorPluginManagerTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Provides a list of configs to test.
|
||||
*/
|
||||
public function providerGetEnabledButtons() {
|
||||
return [
|
||||
'empty' => [
|
||||
[],
|
||||
[]
|
||||
],
|
||||
'1 row, 1 group' => [
|
||||
[
|
||||
// Row 1.
|
||||
[
|
||||
// Group 1.
|
||||
['name' => 'Formatting', 'items' => ['Bold', 'Italic']],
|
||||
]
|
||||
],
|
||||
['Bold', 'Italic']
|
||||
],
|
||||
'1 row, >1 groups' => [
|
||||
[
|
||||
// Row 1.
|
||||
[
|
||||
// Group 1.
|
||||
['name' => 'Formatting', 'items' => ['Bold', 'Italic']],
|
||||
// Group 2.
|
||||
['name' => 'Linking', 'items' => ['Link']],
|
||||
],
|
||||
],
|
||||
['Bold', 'Italic', 'Link']
|
||||
],
|
||||
'2 rows, 1 group each' => [
|
||||
[
|
||||
// Row 1.
|
||||
[
|
||||
// Group 1.
|
||||
['name' => 'Formatting', 'items' => ['Bold', 'Italic']],
|
||||
],
|
||||
// Row 2.
|
||||
[
|
||||
// Group 1.
|
||||
['name' => 'Tools', 'items' => ['Source']],
|
||||
],
|
||||
],
|
||||
['Bold', 'Italic', 'Source'],
|
||||
],
|
||||
'2 rows, >1 groups each' => [
|
||||
[
|
||||
// Row 1.
|
||||
[
|
||||
// Group 1.
|
||||
['name' => 'Formatting', 'items' => ['Bold', 'Italic']],
|
||||
// Group 2.
|
||||
['name' => 'Linking', 'items' => ['Link']],
|
||||
],
|
||||
// Row 2.
|
||||
[
|
||||
// Group 1.
|
||||
['name' => 'Tools', 'items' => ['Source']],
|
||||
// Group 2.
|
||||
['name' => 'Advanced', 'items' => ['Llama']],
|
||||
],
|
||||
],
|
||||
['Bold', 'Italic', 'Link', 'Source', 'Llama']
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getEnabledButtons
|
||||
* @dataProvider providerGetEnabledButtons
|
||||
*/
|
||||
public function testGetEnabledButtons(array $toolbar_rows, array $expected_buttons) {
|
||||
$editor= $this->prophesize(Editor::class);
|
||||
$editor->getSettings()
|
||||
->willReturn(['toolbar' => ['rows' => $toolbar_rows]]);
|
||||
|
||||
$enabled_buttons = CKEditorPluginManager::getEnabledButtons($editor->reveal());
|
||||
$this->assertEquals($expected_buttons, $enabled_buttons);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\ckeditor\Unit\Plugin\CKEditorPlugin;
|
||||
|
||||
use Drupal\ckeditor\Plugin\CKEditorPlugin\Language;
|
||||
use Drupal\Core\Language\LanguageManager;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\ckeditor\Plugin\CKEditorPlugin\Language
|
||||
*
|
||||
* @group ckeditor
|
||||
*/
|
||||
class LanguageTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The plugin under test.
|
||||
*
|
||||
* @var \Drupal\ckeditor\Plugin\CKEditorPlugin\Language
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->plugin = new Language([], $this->randomMachineName(), []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a list of configs to test.
|
||||
*/
|
||||
public function providerGetConfig() {
|
||||
return [
|
||||
['un', count(LanguageManager::getUnitedNationsLanguageList())],
|
||||
['all', count(LanguageManager::getStandardLanguageList())],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getConfig
|
||||
*
|
||||
* @dataProvider providerGetConfig
|
||||
*/
|
||||
public function testGetConfig($language_list, $expected_number) {
|
||||
$editor = $this->getMockBuilder('Drupal\editor\Entity\Editor')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$editor->expects($this->once())
|
||||
->method('getSettings')
|
||||
->willReturn(['plugins' => ['language' => ['language_list' => $language_list]]]);
|
||||
|
||||
$config = $this->plugin->getConfig($editor);
|
||||
|
||||
$this->assertInternalType('array', $config);
|
||||
$this->assertTrue(in_array('ar:Arabic:rtl', $config['language_list']));
|
||||
$this->assertTrue(in_array('zh-hans:Chinese, Simplified', $config['language_list']));
|
||||
$this->assertTrue(in_array('en:English', $config['language_list']));
|
||||
$this->assertTrue(in_array('fr:French', $config['language_list']));
|
||||
$this->assertTrue(in_array('ru:Russian', $config['language_list']));
|
||||
$this->assertTrue(in_array('ar:Arabic:rtl', $config['language_list']));
|
||||
$this->assertEquals($expected_number, count($config['language_list']));
|
||||
}
|
||||
|
||||
}
|