Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / modules / contrib / htmlawed / src / Plugin / Filter / Filterhtmlawed.php
index 6585918ae62e1e52927499e98342d0d4a3cf5b7c..3a35b72e4348ada67188ac733b5a109d96f400b7 100644 (file)
@@ -12,6 +12,7 @@ use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Url;
 use Drupal\filter\FilterProcessResult;
 use Drupal\filter\Plugin\FilterBase;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 
 /**
  * Provides for use of htmLawed
@@ -36,11 +37,13 @@ use Drupal\filter\Plugin\FilterBase;
 
 class Filterhtmlawed extends FilterBase {
 
+  use StringTranslationTrait;
+
   /**
    * {@inheritdoc}
    */
   public function process($text, $langcode) {
-  
+
     // Use htmLawed filter settings for the $config and $spec arguments to htmLawed();
     // use default values if needed.
     $htmLawed_settings = $this->settings;
@@ -51,13 +54,13 @@ class Filterhtmlawed extends FilterBase {
     if (!is_array($config)) {
       $config = array('safe'=>1, 'elements'=>'a, em, strong, cite, code, ol, ul, li, dl, dt, dd, br, p', 'deny_attribute'=>'id, style');
     }
-    
+
     // If PHP code blocks are to be preserved, hide the special characters
     // like '<' of '<?php'.The 'save_php' parameter is NOT an htmLawed parameter per se.
     if (!empty($config['save_php'])) {
       $text = preg_replace_callback('`<\?php(.+?)\?>|<\?php(.*?)$`sm', function($m){return "\x83?php". str_replace(array('<', '>', '&'), array('&lt;', '&gt;', '&amp;'), $m[1]). (substr($m[0], -2) == '?>' ? "?\84" : '');}, $text);
     }
-    
+
     // If Libraries module (API 3.x) is enabled, use htmLawed library through it;
     // else use the htmLawed library provided with the htmLawed module.
     $module_path = drupal_get_path('module', 'htmlawed');
@@ -71,16 +74,16 @@ class Filterhtmlawed extends FilterBase {
 
     // htmLawed filtering.
     $text = htmLawed($text, $config, $htmLawed_settings['spec']);
-    
+
     // In case Drupal's teaser-break is in use;
     // since htmLawed corrects HTML comments to use the right format.
     $text = str_replace('<!--break -->', '<!--break-->', $text);
-    
+
     // Handle any PHP code preservation.
     if (!empty($config['save_php'])) {
       $text = preg_replace_callback('`\x83\?php(.+?)\?\x84|\x83\?php(.*?)$`sm', function($m){return "<?php". str_replace(array('&amp;', '&lt;', '&gt;'), array('&', '<', '>'), $m[1]). (substr($m[0], -2) == "?\x84" ? "?>" : '');}, $text);
     }
-    
+
     // Return value.
     $result = new FilterProcessResult($text);
     return $result;
@@ -92,7 +95,7 @@ class Filterhtmlawed extends FilterBase {
   public function settingsForm(array $form, FormStateInterface $form_state) {
     $htmLawed_settings = $this->settings;
     $form['config'] = array(
-      '#prefix' => t('<a href=":url">Help</a>', array(':url' => Url::fromUri('base:admin/help/htmlawed')->toString())),
+      '#prefix' => $this->t('<a href=":url">Help</a>', array(':url' => Url::fromUri('base:admin/help/htmlawed')->toString())),
       '#type' => 'textarea',
       '#rows' => '2',
       '#title' => $this->t('Config.'),
@@ -125,11 +128,11 @@ class Filterhtmlawed extends FilterBase {
 
   /**
    * {@inheritdoc}
-   */  
+   */
   public function tips($long = FALSE) {
     $htmLawed_settings = $this->settings;
     $help = !$long ? Html::escape($htmLawed_settings['help']) : Html::escape($htmLawed_settings['helplong']);
-    $help = !empty($help) ? $help : (!$long ? t('HTML markup is restricted/corrected with the htmLawed filter.') : t('HTML markup is restricted/corrected with the @htmLawed filter for compliance with admin. policy and standards and for security. More details about the restrictions in effect may be available elsewhere, such as in the text of the filter-tips of text formats that use htmLawed and on the forms for configuring text formats.', array('@htmLawed' => \Drupal::l('htmLawed', Url::fromUri('http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed')))) . (!\Drupal::currentUser()->hasPermission('administer filters') ? '' : t(' For information on configuring the htmLawed filter, visit the htmLawed module @help section.', array('@help' => \Drupal::l(t('help'), Url::fromUri('base:admin/help/htmlawed'))))));
+    $help = !empty($help) ? $help : (!$long ? $this->t('HTML markup is restricted/corrected with the htmLawed filter.') : $this->t('HTML markup is restricted/corrected with the @htmLawed filter for compliance with admin. policy and standards and for security. More details about the restrictions in effect may be available elsewhere, such as in the text of the filter-tips of text formats that use htmLawed and on the forms for configuring text formats.', array('@htmLawed' => \Drupal::l('htmLawed', Url::fromUri('http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed')))) . (!\Drupal::currentUser()->hasPermission('administer filters') ? '' : $this->t(' For information on configuring the htmLawed filter, visit the htmLawed module @help section.', array('@help' => \Drupal::l($this->t('help'), Url::fromUri('base:admin/help/htmlawed'))))));
     return $help;
   }
 }