How to obtain current presenter in IBarPanel implementation

dakur
Member | 493
+
0
-

Hi, I need to make a decision about whether render tab/panel in Tracy bar or not based on what is the current presenter. But I do not know how to obtain current presenter in there.

I've tried to let DI inject IPresenter, PresenterFactory and Application – none of them worked, loading failed with 0 parameters given, 1 expected. Maybe I have to make an extension to be able to pass something there? Seems like to me when I looked into Nette's RoutingPanel. But what actually should I need? Application? IPresenter implementation? I don't get it.

Can you please point me to the right way how to do it? Thank you.

final class CampaignLinksPanel implements IBarPanel
{

	public function __construct(???)
	{}

	public function getTab(): string
	{
		if ( ! ($this->presenter instanceof SomeClass)) {
			return '';
		}

		return '.......';
	}

	public function getPanel(): string
	{

		if ( ! ($this->presenter instanceof SomeClass)) {
			return '';
		}

		return '.......';
	}
}

dakur
Member | 493
+
0
-

Ok, @jiripudil showed me that this is enough:

tracy:
    bar:
        - MyPanel(@Nette\Application\Application)

I've tried MyPanel(@nette.application) before but that did not work.

David Grudl
Nette Core | 8129
+
+1
-

Because it is @application.application

dakur
Member | 493
+
0
-

David Grudl wrote:

Because it is @application.application

Huh. That's strange as namespace is Nette\Application and package name is nette/application. 🤔

Marek Bartoš
Nette Blogger | 1167
+
+1
-

That's strange as namespace is Nette\Application and package name is nette/application

Extension is registered with name application and every service is prefixed by name of extension ($this->prefix('application')'application.aplication'). It prevents collisions and potentially allows register same extension multiple times.
https://github.com/…igurator.php#L32

Last edited by Mabar (2020-08-28 15:54)

David Grudl
Nette Core | 8129
+
+1
-
image
dakur
Member | 493
+
0
-

Thanks for explanation, even it still seems confusing to me. 🙂 Will try to include DI panel into my workflow, that might help.