Skip to content
Snippets Groups Projects

Issue #3283128: Use date.formatter service to format date values.

@@ -4,6 +4,7 @@ namespace Drupal\recurring_events\Plugin\views\field;
@@ -4,6 +4,7 @@ namespace Drupal\recurring_events\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Drupal\views\ResultRow;
 
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
/**
* Field handler to show the start date of an event series.
* Field handler to show the start date of an event series.
@@ -14,6 +15,22 @@ use Drupal\views\ResultRow;
@@ -14,6 +15,22 @@ use Drupal\views\ResultRow;
*/
*/
class EventSeriesStartDate extends FieldPluginBase {
class EventSeriesStartDate extends FieldPluginBase {
 
/**
 
* The date formatter service.
 
*
 
* @var \Drupal\Core\Datetime\DateFormatterInterface
 
*/
 
protected $dateFormatter;
 
 
/**
 
* {@inheritdoc}
 
*/
 
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
 
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
 
$instance->dateFormatter = $container->get('date.formatter');
 
return $instance;
 
}
 
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
@@ -33,7 +50,7 @@ class EventSeriesStartDate extends FieldPluginBase {
@@ -33,7 +50,7 @@ class EventSeriesStartDate extends FieldPluginBase {
if (!empty($event_start)) {
if (!empty($event_start)) {
$format = \Drupal::config('recurring_events.eventseries.config')->get('date_format');
$format = \Drupal::config('recurring_events.eventseries.config')->get('date_format');
$start_date = $event_start->setTimezone($timezone)->format($format);
$start_date = $this->dateFormatter->format($event_start->getTimestamp(), 'custom', $format, $timezone->getName());
}
}
return $start_date;
return $start_date;
}
}
Loading