BillingPeriodDefaultFormatter.php in Commerce Recurring Framework 8
File
src/Plugin/Field/FieldFormatter/BillingPeriodDefaultFormatter.php
View source
<?php
namespace Drupal\commerce_recurring\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
class BillingPeriodDefaultFormatter extends FormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
$build = [];
foreach ($items as $delta => $item) {
$billing_period = $item
->toBillingPeriod();
$start_date = $billing_period
->getStartDate()
->format('M jS Y H:i:s');
$end_date = $billing_period
->getEndDate()
->format('M jS Y H:i:s');
$build[$delta] = [
'#plain_text' => $start_date . ' - ' . $end_date,
];
}
return $build;
}
}