Commit e16cbbe2 authored by webchick's avatar webchick

Issue #2224427 by Wim Leers, tim.plunkett: Filter order no longer respected.

parent 40f818bb
......@@ -155,6 +155,7 @@ public function filters($instance_id = NULL) {
public function getPluginBag() {
if (!isset($this->filterBag)) {
$this->filterBag = new FilterBag(\Drupal::service('plugin.manager.filter'), $this->filters);
$this->filterBag->sort();
}
return $this->filterBag;
}
......
......@@ -109,7 +109,7 @@ public function form(array $form, array &$form_state) {
// Create filter plugin instances for all available filters, including both
// enabled/configured ones as well as new and not yet unconfigured ones.
$filters = $format->filters()->sort();
$filters = $format->filters();
foreach ($filters as $filter_id => $filter) {
// When a filter is missing, it is replaced by the null filter. Remove it
// here, so that saving the form will remove the missing filter.
......
......@@ -15,7 +15,7 @@
interface FilterFormatInterface extends ConfigEntityInterface {
/**
* Returns the collection of filter pugin instances or an individual plugin instance.
* Returns the ordered collection of filter plugin instances or an individual plugin instance.
*
* @param string $instance_id
* (optional) The ID of a filter plugin instance to return.
......
......@@ -66,10 +66,41 @@ function setUp() {
$full_html_format->save();
}
/**
* Tests that the filter order is respected.
*/
function testCheckMarkupFilterOrder() {
// Create crazy HTML format.
$crazy_format = entity_create('filter_format', array(
'format' => 'crazy',
'name' => 'Crazy',
'weight' => 1,
'filters' => array(
'filter_html_escape' => array(
'weight' => 10,
'status' => 1,
),
'filter_html' => array(
'weight' => -10,
'status' => 1,
'settings' => array(
'allowed_html' => '<p>',
),
),
)
));
$crazy_format->save();
$text = "<p>Llamas are <not> awesome!</p>";
$expected_filtered_text = "&lt;p&gt;Llamas are awesome!&lt;/p&gt;";
$this->assertIdentical(check_markup($text, 'crazy'), $expected_filtered_text, 'Filters applied in correct order.');
}
/**
* Tests the ability to apply only a subset of filters.
*/
function testCheckMarkup() {
function testCheckMarkupFilterSubset() {
$text = "Text with <marquee>evil content and</marquee> a URL: http://drupal.org!";
$expected_filtered_text = "Text with evil content and a URL: <a href=\"http://drupal.org\">http://drupal.org</a>!";
$expected_filter_text_without_html_generators = "Text with evil content and a URL: http://drupal.org!";
......@@ -110,7 +141,7 @@ function testFilterFormatAPI() {
);
$this->assertIdentical(
$filtered_html_format->getFilterTypes(),
array(FilterInterface::TYPE_MARKUP_LANGUAGE, FilterInterface::TYPE_HTML_RESTRICTOR),
array(FilterInterface::TYPE_HTML_RESTRICTOR, FilterInterface::TYPE_MARKUP_LANGUAGE),
'FilterFormatInterface::getFilterTypes() works as expected for the filtered_html format.'
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment