Skip to content

Commit

Permalink
Implement rendering of modules
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolineus committed Sep 3, 2024
1 parent 0e3f221 commit d8b8022
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Reference/ModuleReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Hofff\Contao\Content\Reference;

use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\Model\Registry;
use Contao\ModuleModel;
use Doctrine\DBAL\Connection;
Expand All @@ -16,8 +17,11 @@ final class ModuleReference extends RelatedReference implements CreatesRenderer,
{
use ConfigureRenderer;

public function __construct(Connection $connection, private readonly TranslatorInterface $translator)
{
public function __construct(
Connection $connection,
private readonly TranslatorInterface $translator,
private readonly ContaoFramework $contaoFramework,
) {
parent::__construct($connection);
}

Expand All @@ -41,7 +45,7 @@ public function createRenderer(array $reference, array $config): Renderer
$module->setRow($reference);
}

$renderer = new ModuleRenderer();
$renderer = new ModuleRenderer($this->contaoFramework);
$renderer->setModule($module);

$this->configureRenderer($renderer, $config);
Expand Down
15 changes: 14 additions & 1 deletion src/Renderer/ModuleRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

namespace Hofff\Contao\Content\Renderer;

use Contao\Controller;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\ModuleModel;

final class ModuleRenderer extends AbstractRenderer
{
private ModuleModel|null $module = null;

public function __construct(private ContaoFramework $contaoFramework)
{
parent::__construct();
}

public function getModule(): ModuleModel|null
{
return $this->module;
Expand All @@ -36,7 +43,13 @@ protected function getCacheKey(): string

protected function doRender(): string
{
return '';
if ($this->module === null) {
return '';
}

return $this->contaoFramework
->getAdapter(Controller::class)
->getFrontendModule($this->module->id, $this->getColumn());
}

protected function isProtected(): bool
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<service id="Hofff\Contao\Content\Reference\ModuleReference">
<argument type="service" id="database_connection"/>
<argument type="service" id="translator"/>
<argument type="service" id="contao.framework"/>
<tag name="Hofff\Contao\Content\Reference\Reference"/>
</service>

Expand Down

0 comments on commit d8b8022

Please sign in to comment.