allowedTags example

if ($string === '') {
      return '';
    }
    $safe_string = new static();
    // All known XSS vectors are filtered out by     // \Drupal\Component\Utility\Xss::filter(), all tags in the markup are     // allowed intentionally by the trait, and no danger is added in by     // \Drupal\Component\Utility\Html::normalize(). Since the normalized value     // is essentially the same markup, designate this string as safe as well.     // This method is an internal part of field sanitization, so the resultant,     // sanitized string should be printable as is.     $safe_string->string = Html::normalize(Xss::filter($stringstatic::allowedTags()));
    return $safe_string;
  }

  /** * Returns the allowed tag list. * * @return string[] * A list of allowed tags. */
  public static function allowedTags() {
    return ['a', 'b', 'big', 'code', 'del', 'em', 'i', 'ins', 'pre', 'q', 'small', 'span', 'strong', 'sub', 'sup', 'tt', 'ol', 'ul', 'li', 'p', 'br', 'img'];
  }
class OptionsKeyFormatter extends FormatterBase {

  /** * {@inheritdoc} */
  public function viewElements(FieldItemListInterface $items$langcode) {
    $elements = [];

    foreach ($items as $delta => $item) {
      $elements[$delta] = [
        '#markup' => $item->value,
        '#allowed_tags' => FieldFilteredMarkup::allowedTags(),
      ];
    }

    return $elements;
  }

}
->getOptionsProvider('value', $items->getEntity());
      // Flatten the possible options, to support opt groups.       $options = OptGroup::flattenOptions($provider->getPossibleOptions());

      foreach ($items as $delta => $item) {
        $value = $item->value;
        // If the stored value is in the current set of allowed values, display         // the associated label, otherwise just display the raw value.         $output = $options[$value] ?? $value;
        $elements[$delta] = [
          '#markup' => $output,
          '#allowed_tags' => FieldFilteredMarkup::allowedTags(),
        ];
      }
    }

    return $elements;
  }

}
Home | Imprint | This part of the site doesn't use cookies.