From 1b5aefe84850d188e897ea9ef1794c6a85aa7a5d Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Mon, 22 Feb 2016 00:39:02 +0530 Subject: [PATCH] Revert "Issue #2656278 by miteshmap, walangitan, empesan, ejb503, manmohandream, vaidehi bapat, gadaniels72, luca_cracco, swentel, malaimo29001, nileema.jadhav, sidharthap: Convert "Limit allowed HTML tags" input field to a textarea" This reverts commit 537660254b497158e608a88b11ae8f57566dcd0a. --- .../filter/filter.filter_html.admin.js | 59 +++++++++---------- .../filter/src/Plugin/Filter/FilterHtml.php | 4 +- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/core/modules/filter/filter.filter_html.admin.js b/core/modules/filter/filter.filter_html.admin.js index 3931c5959695..8c9cef64f3a2 100644 --- a/core/modules/filter/filter.filter_html.admin.js +++ b/core/modules/filter/filter.filter_html.admin.js @@ -98,9 +98,6 @@ that.$allowedHTMLFormItem.on('change.updateUserTags', function () { that.userTags = _.difference(that._parseSetting(this.value), that.autoTags); }); - }).on('keyup', function (e) { - if (e.keyCode != 13) return; - $(this).val($(this).val().replace(/\n/g, "")); }); }, @@ -241,38 +238,36 @@ var allowedTags = setting.match(/(<[^>]+>)/g); var sandbox = document.createElement('div'); var rules = {}; - if (allowedTags) { - for (var t = 0; t < allowedTags.length; t++) { - // Let the browser do the parsing work for us. - sandbox.innerHTML = allowedTags[t]; - node = sandbox.firstChild; - tag = (node !== null) ? node.tagName.toLowerCase() : null; + for (var t = 0; t < allowedTags.length; t++) { + // Let the browser do the parsing work for us. + sandbox.innerHTML = allowedTags[t]; + node = sandbox.firstChild; + tag = node.tagName.toLowerCase(); - // Build the Drupal.FilterHtmlRule object. - rule = new Drupal.FilterHTMLRule(); - // We create one rule per allowed tag, so always one tag. - rule.restrictedTags.tags = [tag]; - // Add the attribute restrictions. - attributes = (node !== null) ? node.attributes : ''; - for (var i = 0; i < attributes.length; i++) { - attribute = attributes.item(i); - var attributeName = attribute.nodeName; - // @todo Drupal.FilterHtmlRule does not allow for generic attribute - // value restrictions, only for the "class" and "style" attribute's - // values. The filter_html filter always disallows the "style" - // attribute, so we only need to support "class" attribute value - // restrictions. Fix once https://www.drupal.org/node/2567801 lands. - if (attributeName === 'class') { - var attributeValue = attribute.textContent; - rule.restrictedTags.allowed.classes = attributeValue.split(' '); - } - else { - rule.restrictedTags.allowed.attributes.push(attributeName); - } + // Build the Drupal.FilterHtmlRule object. + rule = new Drupal.FilterHTMLRule(); + // We create one rule per allowed tag, so always one tag. + rule.restrictedTags.tags = [tag]; + // Add the attribute restrictions. + attributes = node.attributes; + for (var i = 0; i < attributes.length; i++) { + attribute = attributes.item(i); + var attributeName = attribute.nodeName; + // @todo Drupal.FilterHtmlRule does not allow for generic attribute + // value restrictions, only for the "class" and "style" attribute's + // values. The filter_html filter always disallows the "style" + // attribute, so we only need to support "class" attribute value + // restrictions. Fix once https://www.drupal.org/node/2567801 lands. + if (attributeName === 'class') { + var attributeValue = attribute.textContent; + rule.restrictedTags.allowed.classes = attributeValue.split(' '); + } + else { + rule.restrictedTags.allowed.attributes.push(attributeName); } - - rules[tag] = rule; } + + rules[tag] = rule; } return rules; }, diff --git a/core/modules/filter/src/Plugin/Filter/FilterHtml.php b/core/modules/filter/src/Plugin/Filter/FilterHtml.php index e89e40547a24..63985ffdd28e 100644 --- a/core/modules/filter/src/Plugin/Filter/FilterHtml.php +++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php @@ -46,10 +46,12 @@ class FilterHtml extends FilterBase { */ public function settingsForm(array $form, FormStateInterface $form_state) { $form['allowed_html'] = array( - '#type' => 'textarea', + '#type' => 'textfield', '#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 lang and dir 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 jump-*. JavaScript event attributes, JavaScript URLs, and CSS are always stripped.'), + '#size' => 250, '#attached' => array( 'library' => array( 'filter/drupal.filter.filter_html.admin',