Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize the framework when formatting DCA values #216

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Contao\ArrayUtil;
use Contao\Config;
use Contao\Controller;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\DataContainer;
use Contao\Date;
use Contao\PageModel;
Expand All @@ -17,8 +18,11 @@

class Formatter
{
public function __construct(private readonly Connection $connection, private readonly RequestStack $requestStack,)
{
public function __construct(
private readonly ContaoFramework $framework,
private readonly Connection $connection,
private readonly RequestStack $requestStack,
) {
}

/**
Expand Down Expand Up @@ -50,6 +54,8 @@ public function datim(int $timestamp): string
*/
public function dcaLabel(string $table, string $field): string
{
$this->framework->initialize();

System::loadLanguageFile($table);
Controller::loadDataContainer($table);

Expand Down Expand Up @@ -86,6 +92,8 @@ public function dcaLabelFromArray(array $fieldConfig): string
*/
public function dcaValue(string $table, string $field, mixed $value, DataContainer $dc = null): mixed
{
$this->framework->initialize();

System::loadLanguageFile('default');
System::loadLanguageFile($table);

Expand Down Expand Up @@ -180,6 +188,8 @@ public function dcaValueFromArray(array $fieldConfig, mixed $value, DataContaine
*/
private function formatDate(int $timestamp, string $type): string
{
$this->framework->initialize();

$request = $this->requestStack->getCurrentRequest();

if (null !== $request && ($pageModel = $request->attributes->get('pageModel')) instanceof PageModel) {
Expand Down
Loading