public function WebformSubmissionValue::getFormattedValue in Pardot Integration 2.x
Get the form field from the form state and apply formatting.
Parameters
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
Return value
mixed The formatted value or null i guess.
File
- src/
Plugin/ PardotFormMapFormatterPlugin/ WebformSubmissionValue.php, line 237
Class
- WebformSubmissionValue
- Plugin to generate a text field and consume tokens for mappings.
Namespace
Drupal\pardot\Plugin\PardotFormMapFormatterPluginCode
public function getFormattedValue(FormStateInterface $form_state) {
// Grab formatting selections and the element.
$options = $this->configuration['properties'];
$element = $this->configuration['element'];
// Get the Webform Submission from the form state.
/** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
$webform_submission = $form_state
->getFormObject()
->getEntity();
// Also grab the Webform.
$webform = $webform_submission
->getWebform();
$webform_element_manager = $this->pluginManagerWebformElement;
// Get all the elements of the webform.
$elements = $webform
->getElementsDecodedAndFlattened();
// Get the plugin instance of the element from the webform.
$element_plugin = $webform_element_manager
->getElementInstance($elements[$element], $webform);
$webform_options['webform_key'] = $element;
$element = $elements[$element];
// Swap out the chosen options from the webform configuration with the settings from this plugin.
$element['#format'] = $options['format'];
$element['#format_items'] = $options['format_items'];
// Get the value with the built in formatText method from the WebformElement plugin.
return $element_plugin
->formatText($element, $webform_submission, $webform_options);
}