You are here

function ContactComponent::_webform_display_civicrm_contact in Webform CiviCRM Integration 8.5

Implements _webform_display_component().

File

src/ContactComponent.php, line 18

Class

ContactComponent
Class ContactComponent

Namespace

Drupal\webform_civicrm

Code

function _webform_display_civicrm_contact($component, $value, $format = 'html') {
  $display = empty($value[0]) ? '' : \Drupal::service('webform_civicrm.utils')
    ->wf_crm_display_name($value[0]);
  if ($format == 'html' && $display && user_access('access CiviCRM')) {
    $display = l($display, 'civicrm/contact/view', [
      'alias' => TRUE,
      'query' => [
        'reset' => 1,
        'cid' => $value[0],
      ],
    ]);
  }
  return [
    '#title' => $component['name'],
    '#weight' => $component['weight'],
    '#theme' => 'display_civicrm_contact',
    '#theme_wrappers' => $format == 'html' ? [
      'webform_element',
    ] : [
      'webform_element_text',
    ],
    '#field_prefix' => '',
    '#field_suffix' => '',
    '#format' => $format,
    '#value' => $display,
    '#translatable' => [
      'title',
    ],
  ];
}