You are here

protected function WebformCard::formatHtmlItem in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_cards/src/Plugin/WebformElement/WebformCard.php \Drupal\webform_cards\Plugin\WebformElement\WebformCard::formatHtmlItem()

Format an element's value as HTML.

Parameters

array $element: An element.

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

array $options: An array of options.

Return value

array|string The element's value formatted as HTML or a render array.

Overrides ContainerBase::formatHtmlItem

File

modules/webform_cards/src/Plugin/WebformElement/WebformCard.php, line 80

Class

WebformCard
Provides a 'card' element.

Namespace

Drupal\webform_cards\Plugin\WebformElement

Code

protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $build = parent::formatHtmlItem($element, $webform_submission, $options);

  // Add edit page link container to preview.
  // @see Drupal.behaviors.webformCards
  if ($build && isset($options['view_mode']) && $options['view_mode'] === 'preview' && $webform_submission
    ->getWebform()
    ->getSetting('wizard_preview_link')) {
    $build['#children']['wizard_page_link'] = [
      '#type' => 'container',
      '#attributes' => [
        'title' => $element['#title'],
        'class' => [
          'webform-card-edit',
        ],
        'data-webform-card' => $element['#webform_key'],
      ],
    ];
  }
  return $build;
}