Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / filter / filter.filter_html.admin.es6.js
index c5809c09e8b2718a56a3728d12a6d9c4ee7a5231..548088397c643f89c8637b8cc713c957a858bf90 100644 (file)
      *   A list of new allowed tags.
      */
     _calculateAutoAllowedTags(userAllowedTags, newFeatures) {
-      let featureName;
-      let feature;
-      let featureRule;
-      let filterRule;
-      let tag;
       const editorRequiredTags = {};
+
       // Map the newly added Text Editor features to Drupal.FilterHtmlRule
       // objects (to allow comparing userTags with autoTags).
-      for (featureName in newFeatures) {
-        if (newFeatures.hasOwnProperty(featureName)) {
-          feature = newFeatures[featureName];
-          for (let f = 0; f < feature.length; f++) {
-            featureRule = feature[f];
-            for (let t = 0; t < featureRule.required.tags.length; t++) {
-              tag = featureRule.required.tags[t];
-              if (!_.has(editorRequiredTags, tag)) {
-                filterRule = new Drupal.FilterHTMLRule();
-                filterRule.restrictedTags.tags = [tag];
-                // @todo Neither Drupal.FilterHtmlRule nor
-                //   Drupal.EditorFeatureHTMLRule allow for generic attribute
-                //   value restrictions, only for the "class" and "style"
-                //   attribute's values to be restricted. 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.
-                filterRule.restrictedTags.allowed.attributes = featureRule.required.attributes.slice(0);
-                filterRule.restrictedTags.allowed.classes = featureRule.required.classes.slice(0);
-                editorRequiredTags[tag] = filterRule;
-              }
-              // The tag is already allowed, add any additionally allowed
-              // attributes.
-              else {
-                filterRule = editorRequiredTags[tag];
-                filterRule.restrictedTags.allowed.attributes = _.union(filterRule.restrictedTags.allowed.attributes, featureRule.required.attributes);
-                filterRule.restrictedTags.allowed.classes = _.union(filterRule.restrictedTags.allowed.classes, featureRule.required.classes);
-              }
+      Object.keys(newFeatures || {}).forEach((featureName) => {
+        const feature = newFeatures[featureName];
+        let featureRule;
+        let filterRule;
+        let tag;
+
+        for (let f = 0; f < feature.length; f++) {
+          featureRule = feature[f];
+          for (let t = 0; t < featureRule.required.tags.length; t++) {
+            tag = featureRule.required.tags[t];
+            if (!_.has(editorRequiredTags, tag)) {
+              filterRule = new Drupal.FilterHTMLRule();
+              filterRule.restrictedTags.tags = [tag];
+              // @todo Neither Drupal.FilterHtmlRule nor
+              //   Drupal.EditorFeatureHTMLRule allow for generic attribute
+              //   value restrictions, only for the "class" and "style"
+              //   attribute's values to be restricted. 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.
+              filterRule.restrictedTags.allowed.attributes = featureRule.required.attributes.slice(0);
+              filterRule.restrictedTags.allowed.classes = featureRule.required.classes.slice(0);
+              editorRequiredTags[tag] = filterRule;
+            }
+            // The tag is already allowed, add any additionally allowed
+            // attributes.
+            else {
+              filterRule = editorRequiredTags[tag];
+              filterRule.restrictedTags.allowed.attributes = _.union(filterRule.restrictedTags.allowed.attributes, featureRule.required.attributes);
+              filterRule.restrictedTags.allowed.classes = _.union(filterRule.restrictedTags.allowed.classes, featureRule.required.classes);
             }
           }
         }
-      }
+      });
 
       // Now compare userAllowedTags with editorRequiredTags, and build
       // autoAllowedTags, which contains:
       // - any tags in editorRequiredTags that already exists in userAllowedTags
       //   but does not allow all attributes or attribute values
       const autoAllowedTags = {};
-      for (tag in editorRequiredTags) {
+      Object.keys(editorRequiredTags).forEach((tag) => {
         // If userAllowedTags does not contain a rule for this editor-required
         // tag, then add it to the list of automatically allowed tags.
         if (!_.has(userAllowedTags, tag)) {
             autoAllowedTags[tag].restrictedTags.allowed.classes = _.union(allowedClasses, requiredClasses);
           }
         }
-      }
+      });
 
       return autoAllowedTags;
     },