Chris@0: getSetting('text source') === NULL) { Chris@0: throw new \InvalidArgumentException("The definition's 'text source' key has to specify the name of the text property to be processed."); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getValue() { Chris@0: if ($this->processed !== NULL) { Chris@14: return FilteredMarkup::create($this->processed->getProcessedText()); Chris@0: } Chris@0: Chris@0: $item = $this->getParent(); Chris@0: $text = $item->{($this->definition->getSetting('text source'))}; Chris@0: Chris@14: // Avoid doing unnecessary work on empty strings. Chris@0: if (!isset($text) || $text === '') { Chris@14: $this->processed = new FilterProcessResult(''); Chris@0: } Chris@0: else { Chris@14: $build = [ Chris@14: '#type' => 'processed_text', Chris@14: '#text' => $text, Chris@14: '#format' => $item->format, Chris@14: '#filter_types_to_skip' => [], Chris@14: '#langcode' => $item->getLangcode(), Chris@14: ]; Chris@14: // Capture the cacheability metadata associated with the processed text. Chris@14: $processed_text = $this->getRenderer()->renderPlain($build); Chris@14: $this->processed = FilterProcessResult::createFromRenderArray($build)->setProcessedText((string) $processed_text); Chris@0: } Chris@14: return FilteredMarkup::create($this->processed->getProcessedText()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setValue($value, $notify = TRUE) { Chris@0: $this->processed = $value; Chris@0: // Notify the parent of any changes. Chris@0: if ($notify && isset($this->parent)) { Chris@0: $this->parent->onChange($this->name); Chris@0: } Chris@0: } Chris@0: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function getCacheTags() { Chris@14: $this->getValue(); Chris@14: return $this->processed->getCacheTags(); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function getCacheContexts() { Chris@14: $this->getValue(); Chris@14: return $this->processed->getCacheContexts(); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function getCacheMaxAge() { Chris@14: $this->getValue(); Chris@14: return $this->processed->getCacheMaxAge(); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Returns the renderer service. Chris@14: * Chris@14: * @return \Drupal\Core\Render\RendererInterface Chris@14: */ Chris@14: protected function getRenderer() { Chris@14: return \Drupal::service('renderer'); Chris@14: } Chris@14: Chris@0: }