You are here

protected function ContainerBase::formatCustomItem in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/ContainerBase.php \Drupal\webform\Plugin\WebformElement\ContainerBase::formatCustomItem()

Format an element's item using custom HTML or plain text.

Parameters

string $type: The format type, HTML or Text.

array $element: An element.

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

array $options: An array of options.

array $context: (optional) Context to be passed to inline Twig template.

Return value

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

Overrides WebformElementBase::formatCustomItem

File

src/Plugin/WebformElement/ContainerBase.php, line 215

Class

ContainerBase
Provides a base 'container' class.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatCustomItem($type, array &$element, WebformSubmissionInterface $webform_submission, array $options = [], array $context = []) {
  $name = strtolower($type);

  // Parse children from template and children to context.
  $template = trim($element['#format_' . $name]);
  if (strpos($template, 'children') !== FALSE) {

    /** @var \Drupal\webform\WebformSubmissionViewBuilderInterface $view_builder */
    $view_builder = \Drupal::entityTypeManager()
      ->getViewBuilder('webform_submission');
    $context['children'] = $view_builder
      ->buildElements($element, $webform_submission, $options, $name);
  }
  return parent::formatCustomItem($type, $element, $webform_submission, $options, $context);
}