Split TalkExtension into ExperienceExtension

This commit is contained in:
Oliver Davies 2024-08-04 12:38:18 +01:00
parent 143d1e4f67
commit 90c43e9780
3 changed files with 31 additions and 7 deletions

View file

@ -12,6 +12,9 @@ sculpin_content_types:
permalink: /talks/:basename/
services:
Modules\Experience\TwigExtension\ExperienceTwigExtension:
tags:
- {name: twig.extension}
Modules\Talk\TwigExtension\TalkTwigExtension:
tags:
- {name: twig.extension}

View file

@ -0,0 +1,27 @@
<?php
namespace Modules\Experience\TwigExtension;
use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class ExperienceTwigExtension extends AbstractExtension
{
public function getFunctions(): array
{
return [
new TwigFunction('get_years_of_experience', [$this, 'getYearsOfExperience']),
];
}
public function getName(): string
{
return 'modules.experience';
}
public function getYearsOfExperience(): int
{
return (new \DateTimeImmutable())->format('Y') - 2007;
}
}

View file

@ -12,13 +12,12 @@ class TalkTwigExtension extends AbstractExtension
{
return [
new TwigFunction('get_past_talk_count', [$this, 'getPastTalkCount']),
new TwigFunction('get_years_of_experience', [$this, 'getYearsOfExperience']),
];
}
public function getName(): string
{
return 'app.opdavies_twig_extension';
return 'modules.talk';
}
public function getPastTalkCount(array $talks): int
@ -36,9 +35,4 @@ class TalkTwigExtension extends AbstractExtension
)
->count();
}
public function getYearsOfExperience(): int
{
return (new \DateTimeImmutable())->format('Y') - 2007;
}
}