You are here

public function WebformOptionsCustom::getPreview in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_options_custom/src/Entity/WebformOptionsCustom.php \Drupal\webform_options_custom\Entity\WebformOptionsCustom::getPreview()

Get the custom options element preview.

Return value

array The custom options element preview.

Overrides WebformOptionsCustomInterface::getPreview

File

modules/webform_options_custom/src/Entity/WebformOptionsCustom.php, line 329

Class

WebformOptionsCustom
Defines the webform options custom entity.

Namespace

Drupal\webform_options_custom\Entity

Code

public function getPreview() {
  $element = [
    '#title' => $this
      ->label(),
  ] + $this
    ->getElement();

  // Set default #options.
  if (empty($element['#options'])) {
    $element['#options'] = [
      'one' => t('One -- This is the number 1.'),
      'two' => t('Two -- This is the number 2.'),
      'three' => t('Three -- This is the number 3.'),
    ];
  }

  // Set assets (CSS and JavaScript).
  $assets = '';
  if ($this->css) {
    $assets .= '<style>' . $this->css . '</style>';
  }
  if ($this->javascript) {
    $assets .= '<script>' . $this->javascript . '</script>';
  }
  if ($assets) {
    $element['#prefix'] = Markup::create($assets);
  }
  return $element;
}