Issue #3261599 by hooroomoo, Wim Leers, lauriii: Use CKEditor 5's native <ol start> support (and also support <ol reversed>)
parent
22dab5e4e8
commit
953a69bf53
|
@ -352,11 +352,21 @@ ckeditor5_linkMedia:
|
|||
|
||||
ckeditor5_list:
|
||||
ckeditor5:
|
||||
plugins: [list.List]
|
||||
plugins:
|
||||
- list.List
|
||||
- list.ListProperties
|
||||
config:
|
||||
list:
|
||||
properties:
|
||||
reversed: true
|
||||
startIndex: true
|
||||
# @todo Make this configurable in https://www.drupal.org/project/drupal/issues/3274635
|
||||
styles: false
|
||||
drupal:
|
||||
label: List
|
||||
library: core/ckeditor5.list
|
||||
admin_library: ckeditor5/admin.list
|
||||
class: Drupal\ckeditor5\Plugin\CKEditor5Plugin\ListPlugin
|
||||
toolbar_items:
|
||||
bulletedList:
|
||||
label: Bulleted list
|
||||
|
@ -364,7 +374,7 @@ ckeditor5_list:
|
|||
label: Numbered list
|
||||
elements:
|
||||
- <ul>
|
||||
- <ol>
|
||||
- <ol reversed start>
|
||||
- <li>
|
||||
|
||||
ckeditor5_horizontalLine:
|
||||
|
|
|
@ -85,3 +85,19 @@ ckeditor5.plugin.ckeditor5_sourceEditing:
|
|||
label: 'Allowed Tag'
|
||||
constraints:
|
||||
SourceEditingRedundantTags: []
|
||||
|
||||
# Plugin \Drupal\ckeditor5\Plugin\CKEditor5Plugin\ListPlugin
|
||||
ckeditor5.plugin.ckeditor5_list:
|
||||
type: mapping
|
||||
label: List
|
||||
mapping:
|
||||
reversed:
|
||||
type: boolean
|
||||
label: 'Allow reverse list'
|
||||
constraints:
|
||||
NotNull: []
|
||||
startIndex:
|
||||
type: boolean
|
||||
label: 'Allow start index'
|
||||
constraints:
|
||||
NotNull: []
|
||||
|
|
|
@ -59,6 +59,7 @@ use Drupal\filter\FilterFormatInterface;
|
|||
* },
|
||||
* cke5_plugin_elements_subset_configuration = {
|
||||
* "ckeditor5_heading",
|
||||
* "ckeditor5_list",
|
||||
* }
|
||||
* )
|
||||
*
|
||||
|
@ -226,6 +227,19 @@ class Core extends PluginBase implements CKEditor4To5UpgradePluginInterface {
|
|||
}
|
||||
return $configuration;
|
||||
|
||||
case 'ckeditor5_list':
|
||||
$restrictions = $text_format->getHtmlRestrictions();
|
||||
if ($restrictions === FALSE) {
|
||||
// The default is to allow a reversed list and a start index, which makes sense when there
|
||||
// are no restrictions.
|
||||
// @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\ListPlugin::default_configuration()
|
||||
return NULL;
|
||||
}
|
||||
$configuration = [];
|
||||
$configuration['reversed'] = !empty($restrictions['allowed']['ol']['reversed']);
|
||||
$configuration['startIndex'] = !empty($restrictions['allowed']['ol']['start']);
|
||||
return $configuration;
|
||||
|
||||
default:
|
||||
throw new \OutOfBoundsException();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\ckeditor5\Plugin\CKEditor5Plugin;
|
||||
|
||||
use Drupal\ckeditor5\Plugin\CKEditor5PluginConfigurableInterface;
|
||||
use Drupal\ckeditor5\Plugin\CKEditor5PluginConfigurableTrait;
|
||||
use Drupal\ckeditor5\Plugin\CKEditor5PluginDefault;
|
||||
use Drupal\ckeditor5\Plugin\CKEditor5PluginElementsSubsetInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\editor\EditorInterface;
|
||||
|
||||
/**
|
||||
* CKEditor 5 List plugin.
|
||||
*
|
||||
* @internal
|
||||
* Plugin classes are internal.
|
||||
*/
|
||||
class ListPlugin extends CKEditor5PluginDefault implements CKEditor5PluginConfigurableInterface, CKEditor5PluginElementsSubsetInterface {
|
||||
|
||||
use CKEditor5PluginConfigurableTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return ['reversed' => TRUE, 'startIndex' => TRUE];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$form['reversed'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Allow the user to reverse an ordered list'),
|
||||
'#default_value' => $this->configuration['reversed'],
|
||||
];
|
||||
$form['startIndex'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Allow the user to specify the start index of an ordered list'),
|
||||
'#default_value' => $this->configuration['startIndex'],
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
$form_value = $form_state->getValue('reversed');
|
||||
$form_state->setValue('reversed', (bool) $form_value);
|
||||
$form_value = $form_state->getValue('startIndex');
|
||||
$form_state->setValue('startIndex', (bool) $form_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->configuration['reversed'] = $form_state->getValue('reversed');
|
||||
$this->configuration['startIndex'] = $form_state->getValue('startIndex');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDynamicPluginConfig(array $static_plugin_config, EditorInterface $editor): array {
|
||||
$static_plugin_config['list']['properties'] = array_merge(
|
||||
$static_plugin_config['list']['properties'],
|
||||
$this->getConfiguration()
|
||||
);
|
||||
return $static_plugin_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getElementsSubset(): array {
|
||||
$subset = $this->getPluginDefinition()->getElements();
|
||||
$subset = array_diff($subset, ['<ol reversed start>']);
|
||||
$reversed_enabled = $this->getConfiguration()['reversed'];
|
||||
$start_index_enabled = $this->getConfiguration()['startIndex'];
|
||||
$subset[] = "<ol" . ($reversed_enabled ? ' reversed' : '') . ($start_index_enabled ? ' start' : '') . '>';
|
||||
return $subset;
|
||||
}
|
||||
|
||||
}
|
|
@ -329,7 +329,9 @@ class CKEditor5PluginManager extends DefaultPluginManager implements CKEditor5Pl
|
|||
// work: otherwise it would not be able to know which plugins to enable.
|
||||
elseif (isset($editor)) {
|
||||
$subset = $this->getPlugin($id, $editor)->getElementsSubset();
|
||||
$subset_violations = array_diff($subset, $defined_elements);
|
||||
$subset_restrictions = HTMLRestrictions::fromString(implode($subset));
|
||||
$defined_restrictions = HTMLRestrictions::fromString(implode($defined_elements));
|
||||
$subset_violations = $subset_restrictions->diff($defined_restrictions)->toCKEditor5ElementsArray();
|
||||
if (!empty($subset_violations)) {
|
||||
throw new \LogicException(sprintf('The "%s" CKEditor 5 plugin implements ::getElementsSubset() and did not return a subset, the following tags are absent from the plugin definition: "%s".', $id, implode(' ', $subset_violations)));
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class CKEditor5AllowedTagsTest extends CKEditor5TestBase {
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $defaultElementsAfterUpdatingToCkeditor5 = '<br> <p> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol start type> <img src alt data-entity-type data-entity-uuid> <strong> <em> <code> <li>';
|
||||
protected $defaultElementsAfterUpdatingToCkeditor5 = '<br> <p> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol type start> <img src alt data-entity-type data-entity-uuid> <strong> <em> <code> <li>';
|
||||
|
||||
/**
|
||||
* Test enabling CKEditor 5 in a way that triggers validation.
|
||||
|
|
|
@ -13,7 +13,7 @@ use Drupal\Tests\TestFileCreationTrait;
|
|||
use Drupal\user\RoleInterface;
|
||||
use Symfony\Component\Validator\ConstraintViolation;
|
||||
|
||||
// cspell:ignore esque upcasted
|
||||
// cspell:ignore esque splitbutton upcasted
|
||||
|
||||
/**
|
||||
* Tests for CKEditor5.
|
||||
|
@ -23,7 +23,6 @@ use Symfony\Component\Validator\ConstraintViolation;
|
|||
*/
|
||||
class CKEditor5Test extends CKEditor5TestBase {
|
||||
|
||||
use CKEditor5TestTrait;
|
||||
use TestFileCreationTrait;
|
||||
use CKEditor5TestTrait;
|
||||
|
||||
|
@ -446,6 +445,93 @@ class CKEditor5Test extends CKEditor5TestBase {
|
|||
$assert_session->responseContains('<p>This is a <em>test!</em></p>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests list plugin.
|
||||
*/
|
||||
public function testListPlugin() {
|
||||
FilterFormat::create([
|
||||
'format' => 'test_format',
|
||||
'name' => 'CKEditor 5 with list',
|
||||
'roles' => [RoleInterface::AUTHENTICATED_ID],
|
||||
])->save();
|
||||
Editor::create([
|
||||
'format' => 'test_format',
|
||||
'editor' => 'ckeditor5',
|
||||
'settings' => [
|
||||
'toolbar' => [
|
||||
'items' => ['sourceEditing', 'numberedList'],
|
||||
],
|
||||
'plugins' => [
|
||||
'ckeditor5_list' => [
|
||||
'reversed' => FALSE,
|
||||
'startIndex' => FALSE,
|
||||
],
|
||||
'ckeditor5_sourceEditing' => [
|
||||
'allowed_tags' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
])->save();
|
||||
$this->assertSame([], array_map(
|
||||
function (ConstraintViolation $v) {
|
||||
return (string) $v->getMessage();
|
||||
},
|
||||
iterator_to_array(CKEditor5::validatePair(
|
||||
Editor::load('test_format'),
|
||||
FilterFormat::load('test_format')
|
||||
))
|
||||
));
|
||||
$ordered_list_html = '<ol><li>apple</li><li>banana</li><li>cantaloupe</li></ol>';
|
||||
$page = $this->getSession()->getPage();
|
||||
$assert_session = $this->assertSession();
|
||||
$this->drupalGet('node/add');
|
||||
$page->fillField('title[0][value]', 'My test content');
|
||||
$this->pressEditorButton('Source');
|
||||
$source_text_area = $assert_session->waitForElement('css', '.ck-source-editing-area textarea');
|
||||
$source_text_area->setValue($ordered_list_html);
|
||||
// Click source again to make source inactive and have the numbered list
|
||||
// splitbutton active.
|
||||
$this->pressEditorButton('Source');
|
||||
$numbered_list_dropdown_selector = '.ck-splitbutton__arrow';
|
||||
|
||||
// Check that there is no dropdown available for the numbered list because
|
||||
// both reversed and startIndex are FALSE.
|
||||
$assert_session->elementNotExists('css', $numbered_list_dropdown_selector);
|
||||
// Save content so source content is kept after changing the editor config.
|
||||
$page->pressButton('Save');
|
||||
$edit_url = $this->getSession()->getCurrentURL() . '/edit';
|
||||
$this->drupalGet($edit_url);
|
||||
$this->waitForEditor();
|
||||
|
||||
// Enable the reversed functionality.
|
||||
$editor = Editor::load('test_format');
|
||||
$settings = $editor->getSettings();
|
||||
$settings['plugins']['ckeditor5_list']['reversed'] = TRUE;
|
||||
$editor->setSettings($settings);
|
||||
$editor->save();
|
||||
$this->getSession()->reload();
|
||||
$this->waitForEditor();
|
||||
$this->click($numbered_list_dropdown_selector);
|
||||
$reversed_order_button_selector = '.ck.ck-button.ck-numbered-list-properties__reversed-order';
|
||||
$assert_session->elementExists('css', $reversed_order_button_selector);
|
||||
$assert_session->elementTextEquals('css', $reversed_order_button_selector, 'Reversed order');
|
||||
$start_index_element_selector = '.ck.ck-numbered-list-properties__start-index';
|
||||
$assert_session->elementNotExists('css', $start_index_element_selector);
|
||||
|
||||
// Have both the reversed and the start index enabled.
|
||||
$editor = Editor::load('test_format');
|
||||
$settings = $editor->getSettings();
|
||||
$settings['plugins']['ckeditor5_list']['startIndex'] = TRUE;
|
||||
$editor->setSettings($settings);
|
||||
$editor->save();
|
||||
$this->getSession()->reload();
|
||||
$this->waitForEditor();
|
||||
$this->click($numbered_list_dropdown_selector);
|
||||
$assert_session->elementExists('css', $reversed_order_button_selector);
|
||||
$assert_session->elementTextEquals('css', $reversed_order_button_selector, 'Reversed order');
|
||||
$assert_session->elementExists('css', $start_index_element_selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that CKEditor 5 retains filter_html's allowed global attributes.
|
||||
*
|
||||
|
|
|
@ -982,7 +982,8 @@ PHP,
|
|||
|
||||
// Configure the sneaky superset plugin to have a random tag as the subset.
|
||||
$sneaky_plugin_id = 'ckeditor5_plugin_elements_subset_sneakySuperset';
|
||||
$random_tag = "<{$this->randomMachineName()}>";
|
||||
$random_tag_name = strtolower($this->randomMachineName());
|
||||
$random_tag = "<$random_tag_name>";
|
||||
$text_editor = Editor::create([
|
||||
'format' => 'dummy',
|
||||
'editor' => 'ckeditor5',
|
||||
|
|
|
@ -67,6 +67,10 @@ class ConfigurablePluginTest extends KernelTestBase {
|
|||
'ckeditor5_sourceEditing' => [
|
||||
'allowed_tags' => [],
|
||||
],
|
||||
'ckeditor5_list' => [
|
||||
'reversed' => TRUE,
|
||||
'startIndex' => TRUE,
|
||||
],
|
||||
'ckeditor5_imageResize' => [
|
||||
'allow_resize' => TRUE,
|
||||
],
|
||||
|
|
|
@ -460,7 +460,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'<a hreflang>',
|
||||
'<blockquote cite>',
|
||||
'<ul type>',
|
||||
'<ol start type>',
|
||||
'<ol type>',
|
||||
'<h2 id>',
|
||||
'<h3 id>',
|
||||
'<h4 id>',
|
||||
|
@ -483,6 +483,10 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'ckeditor5_language' => [
|
||||
'language_list' => 'un',
|
||||
],
|
||||
'ckeditor5_list' => [
|
||||
'reversed' => FALSE,
|
||||
'startIndex' => TRUE,
|
||||
],
|
||||
],
|
||||
],
|
||||
'expected_superset' => '<span lang dir>',
|
||||
|
@ -500,7 +504,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
[
|
||||
'expected_messages' => [
|
||||
'status' => [
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
],
|
||||
],
|
||||
]
|
||||
|
@ -523,7 +527,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
],
|
||||
'expected_messages' => [
|
||||
'status' => [
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-caption>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-caption>.',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
@ -545,7 +549,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
],
|
||||
'expected_messages' => [
|
||||
'status' => [
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-align>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-align>.',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
@ -571,13 +575,14 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
],
|
||||
'ckeditor5_imageResize' => ['allow_resize' => TRUE],
|
||||
'ckeditor5_language' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_language'],
|
||||
'ckeditor5_list' => ['reversed' => FALSE, 'startIndex' => TRUE],
|
||||
],
|
||||
],
|
||||
'expected_superset' => $basic_html_test_case['expected_superset'],
|
||||
'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'],
|
||||
'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [
|
||||
'status' => [
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h5 id>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h5 id>.',
|
||||
],
|
||||
]),
|
||||
];
|
||||
|
@ -603,13 +608,14 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
],
|
||||
'ckeditor5_imageResize' => ['allow_resize' => TRUE],
|
||||
'ckeditor5_language' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_language'],
|
||||
'ckeditor5_list' => ['reversed' => FALSE, 'startIndex' => TRUE],
|
||||
],
|
||||
],
|
||||
'expected_superset' => $basic_html_test_case['expected_superset'],
|
||||
'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'],
|
||||
'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [
|
||||
'status' => [
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
],
|
||||
]),
|
||||
];
|
||||
|
@ -633,13 +639,14 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
],
|
||||
'ckeditor5_imageResize' => ['allow_resize' => TRUE],
|
||||
'ckeditor5_language' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_language'],
|
||||
'ckeditor5_list' => ['reversed' => FALSE, 'startIndex' => TRUE],
|
||||
],
|
||||
],
|
||||
'expected_superset' => $basic_html_test_case['expected_superset'],
|
||||
'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'],
|
||||
'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [
|
||||
'status' => [
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type>.',
|
||||
],
|
||||
]),
|
||||
];
|
||||
|
@ -662,7 +669,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'status' => [
|
||||
'The following plugins were enabled to support tags that are allowed by this text format: <em class="placeholder">Code (for tags: <code>) Language (for tags: <span>) Code Block (for tags: <pre>)</em>.',
|
||||
$basic_html_test_case['expected_messages']['status'][1],
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
@ -702,7 +709,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [
|
||||
'status' => [
|
||||
'The following plugins were enabled to support specific attributes that are allowed by this text format: <em class="placeholder">Align center ( for tag: <p> to support: class with value(s): text-align-center), Justify ( for tag: <p> to support: class with value(s): text-align-justify)</em>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
],
|
||||
]),
|
||||
];
|
||||
|
@ -725,7 +732,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'],
|
||||
'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [
|
||||
'status' => [
|
||||
"This format's HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin's <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.",
|
||||
"This format's HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin's <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.",
|
||||
],
|
||||
]),
|
||||
];
|
||||
|
@ -748,7 +755,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'],
|
||||
'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [
|
||||
'status' => [
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-*>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-*>.',
|
||||
],
|
||||
]),
|
||||
];
|
||||
|
@ -798,7 +805,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'<a hreflang>',
|
||||
'<blockquote cite>',
|
||||
'<ul type>',
|
||||
'<ol start type>',
|
||||
'<ol type>',
|
||||
'<h2 id>',
|
||||
'<h3 id>',
|
||||
'<h4 id>',
|
||||
|
@ -806,6 +813,10 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'<h6 id>',
|
||||
],
|
||||
],
|
||||
'ckeditor5_list' => [
|
||||
'reversed' => FALSE,
|
||||
'startIndex' => TRUE,
|
||||
],
|
||||
],
|
||||
],
|
||||
'expected_superset' => '<br> <p>',
|
||||
|
@ -816,7 +827,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'status' => [
|
||||
'The following plugins were enabled to support tags that are allowed by this text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>)</em>.',
|
||||
'The following tags were permitted by this format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
'The following tag(s) were added to <em>Limit allowed HTML tags and correct faulty HTML</em>, because they are needed to provide fundamental CKEditor 5 functionality : <br> <p>.',
|
||||
],
|
||||
],
|
||||
|
@ -865,6 +876,10 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'ckeditor5_imageResize' => [
|
||||
'allow_resize' => TRUE,
|
||||
],
|
||||
'ckeditor5_list' => [
|
||||
'reversed' => TRUE,
|
||||
'startIndex' => TRUE,
|
||||
],
|
||||
'ckeditor5_sourceEditing' => [
|
||||
'allowed_tags' => [],
|
||||
],
|
||||
|
@ -914,7 +929,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'<a hreflang>',
|
||||
'<blockquote cite>',
|
||||
'<ul type>',
|
||||
'<ol start type="1 A I">',
|
||||
'<ol type="1 A I">',
|
||||
'<h2 id="jump-*">',
|
||||
'<h3 id>',
|
||||
'<h4 id>',
|
||||
|
@ -922,6 +937,10 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'<h6 id>',
|
||||
],
|
||||
],
|
||||
'ckeditor5_list' => [
|
||||
'reversed' => FALSE,
|
||||
'startIndex' => TRUE,
|
||||
],
|
||||
],
|
||||
],
|
||||
'expected_superset' => '<br> <p>',
|
||||
|
@ -932,7 +951,7 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
|||
'status' => [
|
||||
'The following plugins were enabled to support tags that are allowed by this text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>)</em>.',
|
||||
'The following tags were permitted by this format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol start type="1 A I"> <h2 id="jump-*"> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type="1 A I"> <h2 id="jump-*"> <h3 id> <h4 id> <h5 id> <h6 id>.',
|
||||
'The following tag(s) were added to <em>Limit allowed HTML tags and correct faulty HTML</em>, because they are needed to provide fundamental CKEditor 5 functionality : <br> <p>.',
|
||||
],
|
||||
],
|
||||
|
|
|
@ -128,7 +128,12 @@ class ValidatorsTest extends KernelTestBase {
|
|||
'foobar',
|
||||
],
|
||||
],
|
||||
'plugins' => [],
|
||||
'plugins' => [
|
||||
'ckeditor5_list' => [
|
||||
'reversed' => FALSE,
|
||||
'startIndex' => FALSE,
|
||||
],
|
||||
],
|
||||
],
|
||||
'violations' => [
|
||||
'settings.toolbar.items.5' => 'The provided toolbar item <em class="placeholder">foobar</em> is not valid.',
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\ckeditor5\Unit;
|
||||
|
||||
use Drupal\ckeditor5\Plugin\CKEditor5Plugin\ListPlugin;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\ckeditor5\Plugin\CKEditor5Plugin\ListPlugin
|
||||
* @group ckeditor5
|
||||
* @internal
|
||||
*/
|
||||
class ListPluginTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Provides a list of configs to test.
|
||||
*/
|
||||
public function providerGetDynamicPluginConfig(): array {
|
||||
return [
|
||||
'startIndex is false' => [
|
||||
[
|
||||
'reversed' => TRUE,
|
||||
'startIndex' => FALSE,
|
||||
],
|
||||
[
|
||||
'list' => [
|
||||
'properties' => [
|
||||
'reversed' => TRUE,
|
||||
'startIndex' => FALSE,
|
||||
'styles' => FALSE,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'reversed is false' => [
|
||||
[
|
||||
'reversed' => FALSE,
|
||||
'startIndex' => TRUE,
|
||||
],
|
||||
[
|
||||
'list' => [
|
||||
'properties' => [
|
||||
'reversed' => FALSE,
|
||||
'startIndex' => TRUE,
|
||||
'styles' => FALSE,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'both disabled' => [
|
||||
[
|
||||
'reversed' => FALSE,
|
||||
'startIndex' => FALSE,
|
||||
],
|
||||
[
|
||||
'list' => [
|
||||
'properties' => [
|
||||
'reversed' => FALSE,
|
||||
'startIndex' => FALSE,
|
||||
'styles' => FALSE,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'both enabled' => [
|
||||
[
|
||||
'reversed' => TRUE,
|
||||
'startIndex' => TRUE,
|
||||
],
|
||||
[
|
||||
'list' => [
|
||||
'properties' => [
|
||||
'reversed' => TRUE,
|
||||
'startIndex' => TRUE,
|
||||
'styles' => FALSE,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getDynamicPluginConfig
|
||||
*
|
||||
* @dataProvider providerGetDynamicPluginConfig
|
||||
*/
|
||||
public function testGetDynamicPluginConfig(array $configuration, array $expected_dynamic_config): void {
|
||||
// Read the CKEditor 5 plugin's static configuration from YAML.
|
||||
$ckeditor5_plugin_definitions = Yaml::parseFile(__DIR__ . '/../../../ckeditor5.ckeditor5.yml');
|
||||
$static_plugin_config = $ckeditor5_plugin_definitions['ckeditor5_list']['ckeditor5']['config'];
|
||||
$plugin = new ListPlugin($configuration, 'ckeditor5_list', NULL);
|
||||
$dynamic_plugin_config = $plugin->getDynamicPluginConfig($static_plugin_config, $this->prophesize(Editor::class)
|
||||
->reveal());
|
||||
$this->assertSame($expected_dynamic_config, $dynamic_plugin_config);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue