Commit ec4b7559 authored by xjm's avatar xjm
Browse files

Issue #2656278 by alexpott, miteshmap, droplet, walangitan, empesan, ejb503,...

Issue #2656278 by alexpott, miteshmap, droplet, walangitan, empesan, ejb503, manmohandream, vaidehi bapat, gadaniels72, swentel, jamesdesq, luca_cracco, malaimo29001, Wim Leers, nileema.jadhav: Convert "Limit allowed HTML tags" input field to a textarea
parent 27509d09
......@@ -41,12 +41,10 @@ class FilterHtml extends FilterBase {
public function settingsForm(array $form, FormStateInterface $form_state) {
$form['allowed_html'] = array(
'#type' => 'textfield',
'#type' => 'textarea',
'#title' => $this->t('Allowed HTML tags'),
'#default_value' => $this->settings['allowed_html'],
'#maxlength' => 2048,
'#description' => $this->t('A list of HTML tags that can be used. By default only the <em>lang</em> and <em>dir</em> attributes are allowed for all HTML tags. Each HTML tag may have attributes which are treated as allowed attribute names for that HTML tag. Each attribute may allow all values, or only allow specific values. Attribute names or values may be written as a prefix and wildcard like <em>jump-*</em>. JavaScript event attributes, JavaScript URLs, and CSS are always stripped.'),
'#size' => 250,
'#attached' => array(
'library' => array(
......@@ -70,6 +68,12 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
public function setConfiguration(array $configuration) {
if (isset($configuration['settings']['allowed_html'])) {
// The javascript in core/modules/filter/filter.filter_html.admin.js
// removes new lines and double spaces so, for consistency when javascript
// is disabled, remove them.
$configuration['settings']['allowed_html'] = preg_replace('/\s+/', ' ', $configuration['settings']['allowed_html']);
// Force restrictions to be calculated again.
$this->restrictions = NULL;
......@@ -206,13 +206,13 @@ function testFilterAdmin() {
$this->assertTrue($full_format->access('use', $this->adminUser), 'Admin user may use Full HTML.');
$this->assertFalse($full_format->access('use', $this->webUser), 'Web user may not use Full HTML.');
// Add an additional tag.
// Add an additional tag and extra spaces and returns.
$edit = array();
$edit['filters[filter_html][settings][allowed_html]'] = '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <quote>';
$edit['filters[filter_html][settings][allowed_html]'] = "<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>\r\n<quote>";
$this->drupalPostForm('admin/config/content/formats/manage/' . $restricted, $edit, t('Save configuration'));
$this->drupalGet('admin/config/content/formats/manage/' . $restricted);
$this->assertFieldByName('filters[filter_html][settings][allowed_html]', $edit['filters[filter_html][settings][allowed_html]'], 'Allowed HTML tag added.');
$this->assertFieldByName('filters[filter_html][settings][allowed_html]', "<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <quote>", 'Allowed HTML tag added.');
$elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', array(
':first' => 'filters[' . $first_filter . '][weight]',
......@@ -79,4 +79,18 @@ public function providerFilterAttributes() {
* @covers ::setConfiguration
public function testSetConfiguration() {
$configuration['settings'] = [
// New lines and spaces are replaced with a single space.
'allowed_html' => "<a> <br>\r\n <p>",
'filter_html_help' => 1,
'filter_html_nofollow' => 0,
$filter = new FilterHtml($configuration, 'filter_html', ['provider' => 'test']);
$this->assertSame('<a> <br> <p>', $filter->getConfiguration()['settings']['allowed_html']);
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