You are here

function social_event_preprocess_field in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_event/social_event.module \social_event_preprocess_field()
  2. 10.0.x modules/social_features/social_event/social_event.module \social_event_preprocess_field()
  3. 10.1.x modules/social_features/social_event/social_event.module \social_event_preprocess_field()
  4. 10.2.x modules/social_features/social_event/social_event.module \social_event_preprocess_field()

Implements hook_preprocess_field().

File

modules/social_features/social_event/social_event.module, line 1028
The Social event module.

Code

function social_event_preprocess_field(&$variables) {
  $formatter = $variables['element']['#formatter'];
  if (in_array($formatter, [
    'address_plain',
    'address_default',
  ])) {
    $entity = $variables['element']['#object'];
    if ($entity && $entity instanceof NodeInterface && $entity
      ->getType() === 'event') {
      $social_event_settings = \Drupal::config('social_event.settings');
      $address_visibility_settings = $social_event_settings
        ->get('address_visibility_settings');
      if (isset($address_visibility_settings['street_code_private']) && !empty($address_visibility_settings['street_code_private'])) {
        if (!_social_event_get_enrollment_status($entity)) {
          switch ($formatter) {
            case 'address_plain':
              if (isset($variables['items'][0]['content']['#address_line1'])) {
                $variables['items'][0]['content']['#address_line1'] = NULL;
              }
              if (isset($variables['items'][0]['content']['#postal_code'])) {
                $variables['items'][0]['content']['#postal_code'] = NULL;
              }
              break;
            case 'address_default':
              if (isset($variables['items'][0]['content']['address_line1']['#value'])) {
                $variables['items'][0]['content']['address_line1']['#value'] = '';
              }
              if (isset($variables['items'][0]['content']['postal_code']['#value'])) {
                $variables['items'][0]['content']['postal_code']['#value'] = '';
              }
              break;
          }
        }
      }
    }
  }
}