Skip to content

Commit

Permalink
Initialize the framework when formatting DCA values
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Jan 29, 2024
1 parent c211255 commit fc9eaf4
Showing 1 changed file with 12 additions and 2 deletions.
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

0 comments on commit fc9eaf4

Please sign in to comment.