Skip to content
Snippets Groups Projects
Commit c8e8ca83 authored by Davyd Burianuvatyi's avatar Davyd Burianuvatyi
Browse files

Issue #3341675: Add data for create event in calendar

parent f2b5fc6f
Branches
Tags 1.0.13
1 merge request!16Resolve #3343868 "Initial implementation"
......@@ -3,12 +3,16 @@
namespace Drupal\ws_event\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Link;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\Markup;
use Drupal\Core\Routing\CurrentRouteMatch;
use Drupal\Core\Url;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\node\NodeInterface;
use Drupal\ws_event\EventDataHelper;
use LinkedIn\Exception;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -53,6 +57,13 @@ class EventInfoBlock extends BlockBase implements ContainerFactoryPluginInterfac
*/
protected $eventDataHelper;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new EventInfoBlock instance.
*
......@@ -70,12 +81,13 @@ class EventInfoBlock extends BlockBase implements ContainerFactoryPluginInterfac
* * @param \Drupal\ws_event\EventDataHelper $eventDataHelper
* Event data helper service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, CurrentRouteMatch $currentRouteMatch, EventDataHelper $eventDataHelper, LoggerChannelFactoryInterface $loggerFactory) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, CurrentRouteMatch $currentRouteMatch, EventDataHelper $eventDataHelper, LoggerChannelFactoryInterface $loggerFactory, EntityTypeManagerInterface $entityTypeManager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentRouteMatch = $currentRouteMatch;
$this->eventDataHelper = $eventDataHelper;
$this->node = $currentRouteMatch->getParameter('node');
$this->logger = $loggerFactory->get('y_lb');
$this->entityTypeManager = $entityTypeManager;
}
/**
......@@ -88,7 +100,8 @@ class EventInfoBlock extends BlockBase implements ContainerFactoryPluginInterfac
$plugin_definition,
$container->get('current_route_match'),
$container->get('ws_event.event_data_helper'),
$container->get('logger.factory')
$container->get('logger.factory'),
$container->get('entity_type.manager'),
);
}
......@@ -125,9 +138,57 @@ class EventInfoBlock extends BlockBase implements ContainerFactoryPluginInterfac
'#location_address' => $address,
'#location_directions' => $directions,
];
if ($atcData = $this->getAtcData()) {
$build['#atc'] = $atcData;
}
return $build;
}
/**
* Add location and date information to event
*
* @return array
*/
protected function getAtcData() {
$datesField = $this->node->get('field_event_dates')->getValue();
if (empty($datesField[0])) {
return [];
}
$timezone = date_default_timezone_get();
$startDt = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $datesField[0]['value'], DateTimeItemInterface::STORAGE_TIMEZONE);
$startDt->setTimezone(timezone_open($timezone));
$endDt = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $datesField[0]['end_value'], DateTimeItemInterface::STORAGE_TIMEZONE);
$endDt->setTimezone(timezone_open($timezone));
$description = '';
$descriptionValue = $this->node->get('body')->getValue();
if (!empty($descriptionValue) && ($description = $descriptionValue[0]['value'])) {
$description = strip_tags($description);
$description = strlen($description) > 300 ? substr($description, 0, 300) . ' ...' : $description;
}
$datesAtc = [
'atc_date_start' => $startDt->format('Y-m-d H:i:s', ['timezone' => $timezone]),
'atc_date_end' => $endDt->format('Y-m-d H:i:s', ['timezone' => $timezone]),
'atc_timezone' => $timezone,
'atc_title' => $this->node->getTitle(),
'atc_description' => $description,
];
// Get locations.
$locationField = $this->node->get('field_event_location')->getValue();
$locationField = reset($locationField);
$location = $this->entityTypeManager->getStorage('node')->load($locationField['target_id']);
if ($location instanceof NodeInterface) {
$locTitle = $location->getTitle();
$datesAtc['atc_location'] = $locTitle;
$datesAtc['atc_organizer'] = $locTitle;
}
return $datesAtc;
}
/**
* Returns formatted Location address.
*
......
......@@ -45,5 +45,17 @@
{% endif %}
</div>
</div>
<div class="addtocalendar"></div>
<div class="addtocalendar">
{% if content['#atc'] %}
<var class="atc_event">
<var class="atc_date_start">{{ content['#atc'].atc_date_start }}</var>
<var class="atc_date_end">{{ content['#atc'].atc_date_end }}</var>
<var class="atc_timezone">{{ content['#atc'].atc_timezone }}</var>
<var class="atc_title">{{ content['#atc'].atc_title }}</var>
<var class="atc_description">{{ content['#atc'].atc_description }}</var>
<var class="atc_location">{{ content['#atc'].atc_location }}</var>
<var class="atc_organizer">{{ content['#atc'].atc_organizer }}</var>
</var>
{% endif %}
</div>
</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment