Skip to content

Commit

Permalink
fix Controller()->replaceInsertTags deprecated/removed in Contao 5
Browse files Browse the repository at this point in the history
  • Loading branch information
ericges committed Feb 15, 2024
1 parent dbc1e71 commit e1a680b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Util/ModelUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
use Contao\Controller;
use Contao\CoreBundle\Framework\Adapter;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\InsertTag\InsertTagParser;
use Contao\Date;
use Contao\Model;
use Contao\Model\Collection;

class ModelUtil
{
public function __construct(
private ContaoFramework $framework
private ContaoFramework $framework,
private InsertTagParser $insertTagParser
)
{
}
Expand Down Expand Up @@ -95,8 +97,8 @@ public function findModelInstancesBy(string $table, array|string|null $columns,
return null;
}

if (\is_array($values) && true !== $options['skipReplaceInsertTags']) {
$values = array_map([$this->framework->getAdapter(Controller::class), 'replaceInsertTags'], $values);
if (is_array($values) && !$options['skipReplaceInsertTags']) {
$values = array_map(fn($value) => $this->insertTagParser->replace($value), $values);
}

if (empty($columns)) {
Expand Down Expand Up @@ -155,8 +157,8 @@ public function findOneModelInstanceBy(string $table, array $columns, array $val
return null;
}

if (\is_array($values) && !$options['skipReplaceInsertTags']) {
$values = array_map([$this->framework->getAdapter(Controller::class), 'replaceInsertTags'], $values);
if (is_array($values) && !$options['skipReplaceInsertTags']) {
$values = array_map(fn($value) => $this->insertTagParser->replace($value), $values);
}

if (empty($columns)) {
Expand Down

0 comments on commit e1a680b

Please sign in to comment.