public function WebformSubmissionViewBuilder::buildComponents in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformSubmissionViewBuilder.php \Drupal\webform\WebformSubmissionViewBuilder::buildComponents()
Builds the component fields and properties of a set of entities.
Parameters
&$build: The renderable array representing the entity content.
\Drupal\Core\Entity\EntityInterface[] $entities: The entities whose content is being built.
\Drupal\Core\Entity\Display\EntityViewDisplayInterface[] $displays: The array of entity view displays holding the display options configured for the entity components, keyed by bundle name.
string $view_mode: The view mode in which the entity is being viewed.
Overrides EntityViewBuilder::buildComponents
File
- src/
WebformSubmissionViewBuilder.php, line 134
Class
- WebformSubmissionViewBuilder
- Render controller for webform submissions.
Namespace
Drupal\webformCode
public function buildComponents(array &$build, array $entities, array $displays, $view_mode) {
if (empty($entities)) {
return;
}
/** @var \Drupal\webform\WebformSubmissionInterface[] $entities */
foreach ($entities as $id => $webform_submission) {
$webform = $webform_submission
->getWebform();
if ($view_mode === 'preview') {
$options = [
'view_mode' => $view_mode,
'excluded_elements' => $webform
->getSetting('preview_excluded_elements'),
'exclude_empty' => $webform
->getSetting('preview_exclude_empty'),
'exclude_empty_checkbox' => $webform
->getSetting('preview_exclude_empty_checkbox'),
];
}
else {
// Track PDF.
// @see webform_entity_print.module
$route_name = $this->routeMatch
->getRouteName();
$pdf = in_array($route_name, [
'entity_print.view.debug',
'entity_print.view',
]) || \Drupal::request()->request
->get('_webform_entity_print');
$options = [
'view_mode' => $view_mode,
'excluded_elements' => $webform
->getSetting('submission_excluded_elements'),
'exclude_empty' => $webform
->getSetting('submission_exclude_empty'),
'exclude_empty_checkbox' => $webform
->getSetting('submission_exclude_empty_checkbox'),
'pdf' => $pdf,
];
}
switch ($view_mode) {
case 'twig':
// @see \Drupal\webform_entity_print_attachment\Element\WebformEntityPrintAttachment::getFileContent
$build[$id]['data'] = WebformTwigExtension::buildTwigTemplate($webform_submission, $webform_submission->_webform_view_mode_twig);
break;
case 'yaml':
// Note that the YAML view ignores all access controls and excluded
// settings.
$data = $webform_submission
->toArray(TRUE, TRUE);
// Covert computed element value markup to strings to
// 'Object support when dumping a YAML file has been disabled' errors.
WebformElementHelper::convertRenderMarkupToStrings($data);
$build[$id]['data'] = [
'#theme' => 'webform_codemirror',
'#code' => WebformYaml::encode($data),
'#type' => 'yaml',
];
break;
case 'text':
$elements = $webform
->getElementsInitialized();
$build[$id]['data'] = [
'#theme' => 'webform_codemirror',
'#code' => $this
->buildElements($elements, $webform_submission, $options, 'text'),
];
break;
case 'table':
$elements = $webform
->getElementsInitializedFlattenedAndHasValue();
$build[$id]['data'] = $this
->buildTable($elements, $webform_submission, $options);
break;
default:
case 'html':
$elements = $webform
->getElementsInitialized();
$build[$id]['data'] = $this
->buildElements($elements, $webform_submission, $options);
break;
}
}
parent::buildComponents($build, $entities, $displays, $view_mode);
}