You are here

public function WebformElementBase::getValue in Webform 8.5

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

Get an element's submission value.

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 submission value.

Overrides WebformElementInterface::getValue

60 calls to WebformElementBase::getValue()
Address::buildAddress in src/Plugin/WebformElement/Address.php
Build formatted address.
BooleanBase::formatTextItem in src/Plugin/WebformElement/BooleanBase.php
Format an element's value as text.
Checkbox::build in src/Plugin/WebformElement/Checkbox.php
Build an element as text or HTML.
Color::formatHtmlItem in src/Plugin/WebformElement/Color.php
Format an element's value as HTML.
DateBase::formatTextItem in src/Plugin/WebformElement/DateBase.php
Format an element's value as text.

... See full list

1 method overrides WebformElementBase::getValue()
WebformComputedBase::getValue in src/Plugin/WebformElement/WebformComputedBase.php
Get an element's submission value.

File

src/Plugin/WebformElementBase.php, line 1765

Class

WebformElementBase
Provides a base class for a webform element.

Namespace

Drupal\webform\Plugin

Code

public function getValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  if (!isset($element['#webform_key']) && isset($element['#value'])) {
    return $element['#value'];
  }
  $webform_key = isset($options['webform_key']) ? $options['webform_key'] : $element['#webform_key'];
  $value = $webform_submission
    ->getElementData($webform_key);

  // Is value is NULL and there is a #default_value, then use it.
  if ($value === NULL && isset($element['#default_value'])) {
    $value = $element['#default_value'];
  }

  // Return multiple (delta) value or composite (composite_key) value.
  if (is_array($value)) {

    // Return $options['delta'] which is used by tokens.
    // @see _webform_token_get_submission_value()
    if (isset($options['delta'])) {
      $value = isset($value[$options['delta']]) ? $value[$options['delta']] : NULL;
    }

    // Return $options['composite_key'] which is used by composite elements.
    // @see \Drupal\webform\Plugin\WebformElement\WebformCompositeBase::formatTableColumn
    if ($value && isset($options['composite_key'])) {
      $value = isset($value[$options['composite_key']]) ? $value[$options['composite_key']] : NULL;
    }
  }
  return $value;
}