protected function CivicrmContact::formatHtmlItem in Webform CiviCRM Integration 8.5
Format an element's value as HTML.
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 value formatted as HTML or a render array.
Overrides WebformElementBase::formatHtmlItem
File
- src/
Plugin/ WebformElement/ CivicrmContact.php, line 570
Class
- CivicrmContact
- Provides a 'textfield' element.
Namespace
Drupal\webform_civicrm\Plugin\WebformElementCode
protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$value = parent::formatHtmlItem($element, $webform_submission, $options);
$format = $this
->getItemFormat($element);
$cid = $value['#plain_text'] ?? NULL;
if ($format === 'raw' || empty($cid) || !is_numeric($cid)) {
return $value;
}
$utils = \Drupal::service('webform_civicrm.utils');
$contact = $utils
->wf_crm_apivalues('contact', 'get', [
'id' => $cid,
], 'display_name');
if (!empty($contact[$cid])) {
if (empty($options['email']) && \Drupal::currentUser()
->hasPermission('access CiviCRM')) {
unset($value['#plain_text']);
$cidURL = Url::fromUri('internal:/civicrm/contact/view', [
'query' => [
'reset' => 1,
'cid' => $cid,
],
])
->toString();
$value['#markup'] = t('<a href=":link">@name</a>', [
':link' => $cidURL,
'@name' => $contact[$cid],
]);
}
else {
$value['#plain_text'] = $contact[$cid];
}
}
return $value;
}