function TextProcessed::getValue

Same name in other branches
  1. 8.9.x core/modules/text/src/TextProcessed.php \Drupal\text\TextProcessed::getValue()
  2. 10 core/modules/text/src/TextProcessed.php \Drupal\text\TextProcessed::getValue()
  3. 11.x core/modules/text/src/TextProcessed.php \Drupal\text\TextProcessed::getValue()

Overrides TypedData::getValue

3 calls to TextProcessed::getValue()
TextProcessed::getCacheContexts in core/modules/text/src/TextProcessed.php
TextProcessed::getCacheMaxAge in core/modules/text/src/TextProcessed.php
TextProcessed::getCacheTags in core/modules/text/src/TextProcessed.php

File

core/modules/text/src/TextProcessed.php, line 41

Class

TextProcessed
A computed property for processing text with a format.

Namespace

Drupal\text

Code

public function getValue() {
    if ($this->processed !== NULL) {
        return FilteredMarkup::create($this->processed
            ->getProcessedText());
    }
    $item = $this->getParent();
    $text = $item->{$this->definition
        ->getSetting('text source')};
    // Avoid doing unnecessary work on empty strings.
    if (!isset($text) || $text === '') {
        $this->processed = new FilterProcessResult('');
    }
    else {
        $build = [
            '#type' => 'processed_text',
            '#text' => $text,
            '#format' => $item->format,
            '#filter_types_to_skip' => [],
            '#langcode' => $item->getLangcode(),
        ];
        // Capture the cacheability metadata associated with the processed text.
        $processed_text = $this->getRenderer()
            ->renderPlain($build);
        $this->processed = FilterProcessResult::createFromRenderArray($build)->setProcessedText((string) $processed_text);
    }
    return FilteredMarkup::create($this->processed
        ->getProcessedText());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.