You are here

public function SocialAddToCalendarBase::getEventLocation in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_addtocal/src/Plugin/SocialAddToCalendarBase.php \Drupal\social_event_addtocal\Plugin\SocialAddToCalendarBase::getEventLocation()
  2. 10.0.x modules/social_features/social_event/modules/social_event_addtocal/src/Plugin/SocialAddToCalendarBase.php \Drupal\social_event_addtocal\Plugin\SocialAddToCalendarBase::getEventLocation()
  3. 10.1.x modules/social_features/social_event/modules/social_event_addtocal/src/Plugin/SocialAddToCalendarBase.php \Drupal\social_event_addtocal\Plugin\SocialAddToCalendarBase::getEventLocation()
  4. 10.2.x modules/social_features/social_event/modules/social_event_addtocal/src/Plugin/SocialAddToCalendarBase.php \Drupal\social_event_addtocal\Plugin\SocialAddToCalendarBase::getEventLocation()

Returns the event location for calendar.

Parameters

\Drupal\node\NodeInterface $node: The node entity.

Return value

string Event location.

Overrides SocialAddToCalendarInterface::getEventLocation

1 call to SocialAddToCalendarBase::getEventLocation()
SocialAddToCalendarBase::generateSettings in modules/social_features/social_event/modules/social_event_addtocal/src/Plugin/SocialAddToCalendarBase.php
Returns array of event settings for url options.

File

modules/social_features/social_event/modules/social_event_addtocal/src/Plugin/SocialAddToCalendarBase.php, line 114

Class

SocialAddToCalendarBase
Base class for Social add to calendar plugins.

Namespace

Drupal\social_event_addtocal\Plugin

Code

public function getEventLocation(NodeInterface $node) {

  // Get event address values.
  if ($node
    ->get('field_event_address')
    ->isEmpty()) {
    return '';
  }
  $address_value = $node->field_event_address
    ->getValue();
  $address = $address_value[0];
  $location = '';

  // Set event location.
  if (!empty($address['address_line1'])) {
    $location .= $address['address_line1'] . ' ';
  }
  if (!empty($address['address_line2'])) {
    $location .= $address['address_line2'] . ', ';
  }
  if (!empty($address['locality'])) {
    $location .= $address['locality'] . ', ';
  }
  if (!empty($address['administrative_area'])) {
    $location .= $address['administrative_area'] . ' ';
  }
  if (!empty($address['postal_code'])) {
    $location .= $address['postal_code'] . ', ';
  }
  if (!empty($address['country_code'])) {
    $location .= $address['country_code'];
  }
  return $location;
}