RecurringPeriodBase.php in Recurring Time Period 8
File
src/Plugin/RecurringPeriod/RecurringPeriodBase.php
View source
<?php
namespace Drupal\recurring_period\Plugin\RecurringPeriod;
use Drupal\recurring_period\Datetime\Period;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\interval\IntervalPluginManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class RecurringPeriodBase extends PluginBase implements ContainerFactoryPluginInterface, RecurringPeriodInterface {
use StringTranslationTrait;
protected $pluginManagerIntervals;
public function __construct(array $configuration, $plugin_id, $plugin_definition, IntervalPluginManagerInterface $plugin_manager_interval_intervals) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
$this->pluginManagerIntervals = $plugin_manager_interval_intervals;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('plugin.manager.interval.intervals'));
}
public function getLabel() {
return $this->pluginDefinition['label'];
}
public function getDescription() {
return $this->pluginDefinition['description'];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return [];
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function getConfiguration() {
return $this->configuration;
}
public function setConfiguration(array $configuration) {
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
}
public function defaultConfiguration() {
return [];
}
public function calculateDependencies() {
return [];
}
public function calculateStart(\DateTimeImmutable $date) {
return $date;
}
public function calculateEnd(\DateTimeImmutable $start) {
return $this
->calculateDate($start);
}
public function getPeriodLabel(\DateTimeImmutable $start, \DateTimeImmutable $end) {
return '';
}
public function getPeriodFromDate(\DateTimeImmutable $start) {
$end_date = $this
->calculateDate($start);
$label = $this
->getPeriodLabel($start, $end_date);
return new Period($start, $end_date, $label);
}
public function getPeriodContainingDate(\DateTimeImmutable $date) {
$start_date = $this
->calculateStart($date);
$end_date = $this
->calculateDate($date);
$label = $this
->getPeriodLabel($start_date, $end_date);
return new Period($start_date, $end_date, $label);
}
public function getNextPeriod(Period $period) {
$end_date = $period
->getEndDate();
return $this
->getPeriodFromDate($end_date);
}
}