Release 2.19 (#4922)
This commit is contained in:
@@ -37,6 +37,7 @@ final class Extensions extends AbstractExtension
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('report_date', [$this, 'buildReportDate']),
|
||||
new TwigFunction('class_name', [$this, 'getClassName']),
|
||||
new TwigFunction('iso_day_by_name', [$this, 'getIsoDayByName']),
|
||||
new TwigFunction('random_color', [$this, 'randomColor']),
|
||||
@@ -52,6 +53,38 @@ final class Extensions extends AbstractExtension
|
||||
];
|
||||
}
|
||||
|
||||
public function buildReportDate(string|int $year, string|int $month = 1, string|int $day = 1): \DateTimeImmutable
|
||||
{
|
||||
if (\is_string($month)) {
|
||||
$month = (int) $month;
|
||||
}
|
||||
if ($month > 12 || $month < 1) {
|
||||
throw new \InvalidArgumentException('Unknown month: ' . $month);
|
||||
}
|
||||
if ($month < 10) {
|
||||
$month = '0' . $month;
|
||||
}
|
||||
|
||||
if (\is_string($day)) {
|
||||
$day = (int) $day;
|
||||
}
|
||||
if ($day > 31 || $day < 1) {
|
||||
throw new \InvalidArgumentException('Unknown day: ' . $day);
|
||||
}
|
||||
if ($day < 10) {
|
||||
$day = '0' . $day;
|
||||
}
|
||||
|
||||
if (\is_string($year)) {
|
||||
$year = (int) $year;
|
||||
}
|
||||
if ($year < 1980 || $year > 2100) {
|
||||
throw new \InvalidArgumentException('Unknown year: ' . $year);
|
||||
}
|
||||
|
||||
return \DateTimeImmutable::createFromFormat('Y-m-d', $year . '-' . $month . '-' . $day); // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
public function formatReportDate(\DateTimeInterface $dateTime): string
|
||||
{
|
||||
return $dateTime->format(self::REPORT_DATE);
|
||||
|
||||
@@ -189,18 +189,36 @@ final class LocaleFormatExtensions extends AbstractExtension implements LocaleAw
|
||||
return $this->getFormatter()->dayName($dateTime, $short);
|
||||
}
|
||||
|
||||
public function getJavascriptConfiguration(User $user): array
|
||||
public function getJavascriptConfiguration(?User $user = null): array
|
||||
{
|
||||
$language = User::DEFAULT_LANGUAGE;
|
||||
$browserTitle = false;
|
||||
$id = null;
|
||||
$name = 'anonymous';
|
||||
$admin = false;
|
||||
$superAdmin = false;
|
||||
$timezone = date_default_timezone_get();
|
||||
|
||||
if ($user !== null) {
|
||||
$browserTitle = (bool) $user->getPreferenceValue('update_browser_title');
|
||||
$language = $user->getLanguage();
|
||||
$id = $user->getId();
|
||||
$name = $user->getDisplayName();
|
||||
$admin = $user->isAdmin();
|
||||
$superAdmin = $user->isSuperAdmin();
|
||||
$timezone = $user->getTimezone();
|
||||
}
|
||||
|
||||
return [
|
||||
'locale' => $this->locale,
|
||||
'language' => $user->getLanguage(),
|
||||
'language' => $language,
|
||||
'formatDuration' => $this->localeService->getDurationFormat($this->locale),
|
||||
'formatDate' => $this->localeService->getDateFormat($this->locale),
|
||||
'defaultColor' => Constants::DEFAULT_COLOR,
|
||||
'twentyFourHours' => $this->localeService->is24Hour($this->locale),
|
||||
'updateBrowserTitle' => (bool) $user->getPreferenceValue('update_browser_title'),
|
||||
'timezone' => $user->getTimezone(),
|
||||
'user' => ['id' => $user->getId(), 'name' => $user->getDisplayName(), 'admin' => $user->isAdmin(), 'superAdmin' => $user->isSuperAdmin()],
|
||||
'updateBrowserTitle' => $browserTitle,
|
||||
'timezone' => $timezone,
|
||||
'user' => ['id' => $id, 'name' => $name, 'admin' => $admin, 'superAdmin' => $superAdmin],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user