You are here

public function YamlFormElementBase::formatText in YAML Form 8

Format an element's value as plain text.

Parameters

array $element: An element.

array|mixed $value: A value.

array $options: An array of options.

Return value

string The element's value formatted as plain text or a render array.

Overrides YamlFormElementInterface::formatText

6 calls to YamlFormElementBase::formatText()
Password::formatText in src/Plugin/YamlFormElement/Password.php
Format an element's value as plain text.
YamlFormElementBase::buildExportRecord in src/YamlFormElementBase.php
Build an element's export row.
YamlFormElementBase::formatHtml in src/YamlFormElementBase.php
Format an element's value as HTML.
YamlFormRating::formatHtml in src/Plugin/YamlFormElement/YamlFormRating.php
Format an element's value as HTML.
YamlFormSignature::formatText in src/Plugin/YamlFormElement/YamlFormSignature.php
Format an element's value as plain text.

... See full list

13 methods override YamlFormElementBase::formatText()
BooleanBase::formatText in src/Plugin/YamlFormElement/BooleanBase.php
Format an element's value as plain text.
DateBase::formatText in src/Plugin/YamlFormElement/DateBase.php
Format an element's value as plain text.
LanguageSelect::formatText in src/Plugin/YamlFormElement/LanguageSelect.php
Format an element's value as plain text.
OptionsBase::formatText in src/Plugin/YamlFormElement/OptionsBase.php
Format an element's value as plain text.
Password::formatText in src/Plugin/YamlFormElement/Password.php
Format an element's value as plain text.

... See full list

File

src/YamlFormElementBase.php, line 619

Class

YamlFormElementBase
Provides a base class for a form element.

Namespace

Drupal\yamlform

Code

public function formatText(array &$element, $value, array $options = []) {

  // Return empty value.
  if ($value === '' || $value === NULL) {
    return '';
  }

  // Flatten arrays. Generally, $value is a string.
  if (is_array($value) && count($value) == count($value, COUNT_RECURSIVE)) {
    $value = implode(', ', $value);
  }

  // Apply XSS filter to value that contains HTML tags and is not formatted as
  // raw.
  $format = $this
    ->getFormat($element);
  if ($format != 'raw' && is_string($value) && strpos($value, '<') !== FALSE) {
    $value = Xss::filter($value);
  }

  // Format value based on the element type using default settings.
  if (isset($element['#type'])) {

    // Apply #field prefix and #field_suffix to value.
    if (isset($element['#field_prefix'])) {
      $value = $element['#field_prefix'] . $value;
    }
    if (isset($element['#field_suffix'])) {
      $value .= $element['#field_suffix'];
    }
  }
  return $value;
}