public function SocialAddToCalendarBase::getEventDates in Open Social 10.3.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_event/modules/social_event_addtocal/src/Plugin/SocialAddToCalendarBase.php \Drupal\social_event_addtocal\Plugin\SocialAddToCalendarBase::getEventDates()
- 10.0.x modules/social_features/social_event/modules/social_event_addtocal/src/Plugin/SocialAddToCalendarBase.php \Drupal\social_event_addtocal\Plugin\SocialAddToCalendarBase::getEventDates()
- 10.1.x modules/social_features/social_event/modules/social_event_addtocal/src/Plugin/SocialAddToCalendarBase.php \Drupal\social_event_addtocal\Plugin\SocialAddToCalendarBase::getEventDates()
- 10.2.x modules/social_features/social_event/modules/social_event_addtocal/src/Plugin/SocialAddToCalendarBase.php \Drupal\social_event_addtocal\Plugin\SocialAddToCalendarBase::getEventDates()
Returns array of event dates for calendar.
Parameters
\Drupal\node\NodeInterface $node: The node entity.
Return value
array Array of dates values.
Overrides SocialAddToCalendarInterface::getEventDates
1 call to SocialAddToCalendarBase::getEventDates()
- 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 49
Class
- SocialAddToCalendarBase
- Base class for Social add to calendar plugins.
Namespace
Drupal\social_event_addtocal\PluginCode
public function getEventDates(NodeInterface $node) {
// Set default values.
$all_day = FALSE;
$start_date = new DateTime($node->field_event_date->value, new DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE));
$end_date = new DateTime($node->field_event_date_end->value, new DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE));
$date_time = [];
// Set formats for event dates.
$format = $this->pluginDefinition['dateFormat'];
if (date_default_timezone_get() === DateTimeItemInterface::STORAGE_TIMEZONE) {
$format = $this->pluginDefinition['utcDateFormat'];
}
$all_day_format = $this->pluginDefinition['allDayFormat'];
// Check if all day event.
if ($start_date
->format('i') === '01') {
$all_day = TRUE;
}
// Convert date to correct format.
// Set dates array.
if ($all_day) {
$date_time['start'] = $start_date
->format($all_day_format);
$end_date
->modify($this->pluginDefinition['endDateModification']);
$date_time['end'] = $end_date
->format($all_day_format);
}
else {
$start_date
->setTimezone(new DateTimeZone(date_default_timezone_get()));
$end_date
->setTimezone(new DateTimeZone(date_default_timezone_get()));
$date_time['start'] = $start_date
->format($format);
$date_time['end'] = $end_date
->format($format);
}
// Set external values for dates.
$date_time['both'] = $date_time['start'] . '/' . $date_time['end'];
$date_time['all_day'] = $all_day;
return $date_time;
}