Skip to content

Commit 0ff0743

Browse files
committed
feat: Add isVisible() component flag to skip rendering entirely
1 parent 0195b6c commit 0ff0743

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

Component/ComponentViewModel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ComponentViewModel implements ComponentViewModelInterface
1919
protected bool $lazyLoad = false;
2020
protected bool $lazyUpdate = false;
2121
protected bool $allowRendering = true;
22+
protected bool $visible = true;
2223

2324
public function setComponent(ComponentInterface $component): void
2425
{
@@ -186,6 +187,11 @@ public function isAllowRendering(): bool
186187
return $this->allowRendering;
187188
}
188189

190+
public function isVisible(): bool
191+
{
192+
return $this->visible;
193+
}
194+
189195
public function getJsData(): array
190196
{
191197
return [

Component/ComponentViewModelInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function getComponentName(): string;
4545
public function isLazyLoad(): bool;
4646

4747
public function isAllowRendering(): bool;
48+
public function isVisible(): bool;
4849

4950
public function getJsComponentName(): ?string;
5051

Observer/AssignAdditionalBlockVariables.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ private function addComponent(Template $block, ComponentInterface $component): T
6868
$block->setViewModel($viewModel);
6969
$block->setViewModelInstance($viewModel);
7070

71+
if (false === $viewModel->isVisible()) {
72+
$block->setTemplate('Loki_Components::utils/not-visible.phtml'); // @phpstan-ignore bitExpertMagento.setTemplateDisallowedForBlock
73+
}
74+
7175
if (false === $viewModel->isAllowRendering()) {
7276
$block->setTemplate('Loki_Components::utils/not-rendered.phtml'); // @phpstan-ignore bitExpertMagento.setTemplateDisallowedForBlock
7377
$block->setNotRendered(true);

0 commit comments

Comments
 (0)