You are here

public function RollingInterval::getPeriodLabel in Recurring Time Period 8

Gets a label for the period starting from the given date.

This produces a generic label. It may be desirable to override this method in a replacement plugin class.

Parameters

\DateTimeImmutable $start: The date and time to begin the period from.

\DateTimeImmutable $end: The date and time on which the period ends.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup The label.

Overrides RecurringPeriodBase::getPeriodLabel

File

src/Plugin/RecurringPeriod/RollingInterval.php, line 94

Class

RollingInterval
Provides a period based on a rolling interval from the start date.

Namespace

Drupal\recurring_period\Plugin\RecurringPeriod

Code

public function getPeriodLabel(\DateTimeImmutable $start, \DateTimeImmutable $end) {

  // Get our interval values from our configuration.
  $config = $this
    ->getConfiguration();
  $interval_configuration = $config['interval'];

  // The interval plugin ID is the 'period' value.
  $interval_plugin_id = $interval_configuration['period'];
  $interval_plugin_definition = $this->pluginManagerIntervals
    ->getDefinition($interval_plugin_id);
  return $this
    ->t("@count @interval from @start-date", [
    '@count' => $config['interval']['interval'],
    '@interval' => $config['interval']['interval'] == 1 ? $interval_plugin_definition['singular'] : $interval_plugin_definition['plural'],
    '@start-date' => $start
      ->format(\DateTimeInterface::RSS),
  ]);
}