Loading src/OfficeHoursFormatterTrait.php +38 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\office_hours; use Drupal\Component\Utility\Html; use Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItem; /** * Factors out OfficeHoursItemList->getItems()->getRows(). Loading @@ -22,6 +23,8 @@ trait OfficeHoursFormatterTrait { * The settings. * @param array $field_settings * The field settings. * @param array $third_party_settings * The third party settings. * @param $time * A time stamp. Defaults to 'REQUEST_TIME'. * Loading Loading @@ -449,4 +452,39 @@ trait OfficeHoursFormatterTrait { return $office_hours; } /** * A helper variable for keepExceptionDaysInHorizon. * * @var int */ protected static $horizon; /** * Formatter: remove all Exception days behind horizon. * * @param int $horizon * The number of days in the future. * * @return \Drupal\Core\Field\FieldItemListInterface * Filtered Item list. */ public function keepExceptionDaysInHorizon($horizon) { self::$horizon = $horizon; $this->filter(function (OfficeHoursItem $item) { if (!$item->isExceptionDay()) { return TRUE; } if (self::$horizon == NULL) { // Exceptions settings are not set / submodule is disabled. return FALSE; } if ($item->isExceptionDayInRange(self::$horizon)) { return TRUE; } return FALSE; }); return $this; } } Loading
src/OfficeHoursFormatterTrait.php +38 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\office_hours; use Drupal\Component\Utility\Html; use Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItem; /** * Factors out OfficeHoursItemList->getItems()->getRows(). Loading @@ -22,6 +23,8 @@ trait OfficeHoursFormatterTrait { * The settings. * @param array $field_settings * The field settings. * @param array $third_party_settings * The third party settings. * @param $time * A time stamp. Defaults to 'REQUEST_TIME'. * Loading Loading @@ -449,4 +452,39 @@ trait OfficeHoursFormatterTrait { return $office_hours; } /** * A helper variable for keepExceptionDaysInHorizon. * * @var int */ protected static $horizon; /** * Formatter: remove all Exception days behind horizon. * * @param int $horizon * The number of days in the future. * * @return \Drupal\Core\Field\FieldItemListInterface * Filtered Item list. */ public function keepExceptionDaysInHorizon($horizon) { self::$horizon = $horizon; $this->filter(function (OfficeHoursItem $item) { if (!$item->isExceptionDay()) { return TRUE; } if (self::$horizon == NULL) { // Exceptions settings are not set / submodule is disabled. return FALSE; } if ($item->isExceptionDayInRange(self::$horizon)) { return TRUE; } return FALSE; }); return $this; } }