Skip to content

Commit

Permalink
BasePlugin: Setter for global Context
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Oct 8, 2020
1 parent 47b31a8 commit 91e6285
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Plugin/BasePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ abstract class BasePlugin implements Plugin
/** @var mixed[] */
private $smartControlComponentParams = [];

/** @var PluginLinkGenerator|null */
private $linkGenerator;
/** @var Context */
private $context;


final public function run(): void
Expand Down Expand Up @@ -144,11 +144,11 @@ public function terminate(): void
*/
final public function link(string $route = 'Homepage:default', array $params = []): string
{
if ($this->linkGenerator === null) {
if (($linkGenerator = $this->context->getLinkGenerator()) === null) {
throw new \RuntimeException('Link generator failed: Service for "' . PluginLinkGenerator::class . '" does not registered. Did you install baraja-core/cms?');
}

return $this->linkGenerator->link($route, $params);
return $linkGenerator->link($route, $params);
}


Expand Down Expand Up @@ -275,8 +275,8 @@ public function setSmartControlComponentParams(array $params): void
}


final public function setLinkGenerator(PluginLinkGenerator $linkGenerator): void
final public function setContext(Context $context): void
{
$this->linkGenerator = $linkGenerator;
$this->context = $context;
}
}

0 comments on commit 91e6285

Please sign in to comment.