WebformComputedTwig.php in Webform 6.x
File
src/Element/WebformComputedTwig.php
View source
<?php
namespace Drupal\webform\Element;
use Drupal\webform\Twig\WebformTwigExtension;
use Drupal\webform\WebformSubmissionInterface;
class WebformComputedTwig extends WebformComputedBase {
const WHITESPACE_SPACELESS = 'spaceless';
const WHITESPACE_TRIM = 'trim';
public function getInfo() {
return parent::getInfo() + [
'#whitespace' => '',
];
}
public static function computeValue(array $element, WebformSubmissionInterface $webform_submission) {
$theme_manager = \Drupal::service('webform.theme_manager');
if (!$theme_manager
->hasActiveTheme() && PHP_SAPI !== 'cli') {
return '';
}
$whitespace = !empty($element['#whitespace']) ? $element['#whitespace'] : '';
$template = $whitespace === static::WHITESPACE_SPACELESS ? '{% spaceless %}' . $element['#template'] . '{% endspaceless %}' : $element['#template'];
$options = [
'html' => static::getMode($element) === WebformComputedInterface::MODE_HTML,
];
$value = WebformTwigExtension::renderTwigTemplate($webform_submission, $template, $options);
return $whitespace === static::WHITESPACE_TRIM ? trim($value) : $value;
}
}