Overrides \Drupal\Component\Plugin\Context\Context::getContextValue().
Overrides Context::getContextValue
public function getContextValue() {
  $typed_value = parent::getContextValue();
  // If the typed data is complex, pass it on as typed data. Else pass on its
  // plain value, such that e.g. a string will be directly returned as PHP
  // string.
  $is_complex = $typed_value instanceof ComplexDataInterface;
  if (!$is_complex && $typed_value instanceof ListInterface) {
    $is_complex = $typed_value[0] instanceof ComplexDataInterface;
  }
  // @todo We won't need the getType == entity check once #1868004 lands.
  if ($typed_value instanceof TypedDataInterface && (!$is_complex || $typed_value instanceof EntityWrapper)) {
    return $typed_value
      ->getValue();
  }
  return $typed_value;
}