Skip to content

Commit

Permalink
Merge pull request #389 from CPS-IT/feature/1.x/add-variable
Browse files Browse the repository at this point in the history
[FEATURE] Allow modifying a single variable in `BeforeRenderingEvent`
  • Loading branch information
eliashaeussler authored Jan 8, 2025
2 parents 106519d + ecbc6c4 commit c1cdced
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Classes/Event/BeforeRenderingEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ public function setVariables(array $variables): self
return $this;
}

public function addVariable(string $name, mixed $value): self
{
$this->variables[$name] = $value;
return $this;
}

public function removeVariable(string $name): self
{
unset($this->variables[$name]);
return $this;
}

public function getRenderer(): HandlebarsRenderer
{
return $this->renderer;
Expand Down
23 changes: 23 additions & 0 deletions Tests/Unit/Event/BeforeRenderingEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ public function setVariablesModifiesVariables(): void
self::assertSame(['modified' => 'variables'], $this->subject->getVariables());
}

#[Framework\Attributes\Test]
public function addVariableAddsSingleVariable(): void
{
$this->subject->addVariable('foo', 'boo');
$this->subject->addVariable('baz', 'foo');

self::assertSame(
[
'foo' => 'boo',
'baz' => 'foo',
],
$this->subject->getVariables(),
);
}

#[Framework\Attributes\Test]
public function removeVariableRemoveSingleVariable(): void
{
$this->subject->removeVariable('foo');

self::assertSame([], $this->subject->getVariables());
}

#[Framework\Attributes\Test]
public function getRendererReturnsRenderer(): void
{
Expand Down

0 comments on commit c1cdced

Please sign in to comment.