Commit d827cc0a authored by Ivan Doroshenko's avatar Ivan Doroshenko Committed by Owen Bush
Browse files

Issue #3283128 by Matroskeen, owenbush: Use date.formatter service to format date values

parent 0eaad340
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\recurring_events\Plugin\views\field;

use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Field handler to show the start date of an event series.
@@ -14,6 +15,22 @@ use Drupal\views\ResultRow;
 */
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}
   */
@@ -33,7 +50,7 @@ class EventSeriesStartDate extends FieldPluginBase {

    if (!empty($event_start)) {
      $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;
  }