Commit ee79aedb authored by anon's avatar anon Committed by anon

Issue #2751301 by anon: Handle the new data- attributes for text formats with filter_html

parent d0fcf487
/**
* @file
* Send events to add or remove a tags to the filter_html allowed tags.
*/
(function ($, Drupal, document) {
'use strict';
/**
* When enabling the linkit filter, also add linkit rules to filter_html.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attaches linkitFilterHtml behavior.
*/
Drupal.behaviors.linkitFilterHtml = {
attach: function (context) {
var selector = '[data-drupal-selector="edit-filters-linkit-status"]';
var feature = editorFeature();
$(context).find(selector).once('filters-linkit-status').each(function () {
$(this).on('click', function () {
var eventName = $(this).is(':checked') ? 'drupalEditorFeatureAdded' : 'drupalEditorFeatureRemoved';
$(document).trigger(eventName, feature);
});
});
}
};
/**
* Returns a editor feature.
*
* @return {Drupal.EditorFeature}
* A editor feature with linkit specific tags and attributes.
*/
function editorFeature() {
var linkitFeature = new Drupal.EditorFeature('linkit');
var rule = new Drupal.EditorFeatureHTMLRule();
// Tags.
rule.required.tags = ['a'];
rule.allowed.tags = ['a'];
// Attributes.
rule.required.attributes = ['data-entity-type', 'data-entity-uuid', 'title'];
rule.allowed.attributes = ['data-entity-type', 'data-entity-uuid', 'title'];
linkitFeature.addHTMLRule(rule);
return linkitFeature;
}
})(jQuery, Drupal, document);
......@@ -26,6 +26,11 @@ linkit.autocomplete:
- core/jquery.ui.autocomplete
- core/underscore
linkit.filter_html.admin:
version: VERSION
js:
js/linkit.filter_html.admin.js: {}
linkit.imce:
version: VERSION
js:
......
......@@ -138,6 +138,9 @@ class LinkitFilter extends FilterBase implements ContainerFactoryPluginInterface
'#type' => 'checkbox',
'#title' => $this->t('Automatically set the <code>title</code> attribute to that of the (translated) referenced content'),
'#default_value' => $this->settings['title'],
'#attached' => [
'library' => ['linkit/linkit.filter_html.admin'],
],
];
return $form;
}
......
<?php
namespace Drupal\Tests\linkit\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
/**
* Tests the linkit alterations on the text format forms.
*
* @group linkit
*/
class LinkitFormatAdminTest extends JavascriptTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['editor', 'filter', 'linkit'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$account = $this->drupalCreateUser([
'administer filters',
]);
$this->drupalLogin($account);
}
/**
* Tests that linkit filter is toggling the filter_html allowed tags.
*/
public function testToggleLinkitFilter() {
$session = $this->getSession();
$page = $session->getPage();
// Go to add filter page.
$this->drupalGet('admin/config/content/formats/add');
$this->assertSession()->statusCodeEquals(200);
// Enable the 'Limit allowed HTML tags and correct faulty HTML' filter.
$page->findField('filters[filter_html][status]')->check();
$javascript = "(function (){ return jQuery('p.editor-update-message > strong').text(); })()";
$this->assertNotContains('<a href hreflang data-entity-type data-entity-uuid title>', $session->evaluateScript($javascript));
// Enable the 'Linkit filter' filter.
$page->findField('filters[linkit][status]')->check();
$this->assertContains('<a href hreflang data-entity-type data-entity-uuid title>', $session->evaluateScript($javascript));
// Disable the 'Linkit filter' filter.
$page->findField('filters[linkit][status]')->uncheck();
$this->assertNotContains('<a href hreflang data-entity-type data-entity-uuid title>', $session->evaluateScript($javascript));
}
}
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