You are here

public function DefaultValue::getFormattedValue in Pardot Integration 2.x

File

src/Plugin/PardotFormMapFormatterPlugin/DefaultValue.php, line 113

Class

DefaultValue
Plugin to select from the list of fields.

Namespace

Drupal\pardot\Plugin\PardotFormMapFormatterPlugin

Code

public function getFormattedValue(FormStateInterface $form_state) {
  $field_name = $this
    ->getConfiguration()['fields'] ?? FALSE;
  if ($field_name) {
    $value = $form_state
      ->getValue($field_name);
  }
  else {
    $value = NULL;
  }
  if (is_array($value)) {

    // If this is an entity selection we get a target id so lets just get the title.
    $target_id = array_column($value, 'target_id');
    if ($target_id) {
      $value = $this
        ->getEntityReferenceValues($field_name, $form_state);
    }
    else {

      // I think if its not target_id then its value and we will just have all the values in an array.
      $value = implode(',', array_values(array_column($value, 'value')));
    }
  }
  return $value;
}