? ? Pending

User tests: Successful: Unsuccessful:

avatar Fedik
Fedik
11 Jan 2020

Summary of Changes

It would be good to have some Shortkut for Factory::getApplication()->getDocument()->getWebAssetManager(), to use it in layouts.
In a template it is enough to have $this->getWebAssetManager(), but in layouts and other parts it a bit to complex to use Factory::getApplication()->getDocument()->getWebAssetManager().

I am not sure what is good place/name for it. For now I made it as HTMLHelper::webAsset()
That should be used as HTMLHelper::webAsset() (not HTMLHelper::_('webAsset')), it is important to support code navigation and auto-completion.

But I am afraid it can be confusing, because historically all HTML helpers methods should be called as HTMLHelper::_('foobar').

@wilsonge maybe you have a better idea, to make it nicer and not much confusing? ;)
What other place/approach can be for it?

Documentation Changes Required

Add info about this.

avatar Fedik Fedik - open - 11 Jan 2020
avatar Fedik Fedik - change - 11 Jan 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 11 Jan 2020
Category Layout Libraries
avatar wilsonge
wilsonge - comment - 11 Jan 2020

Sorry not a fan of this one. I'd be happy if you wanted to make it a class property in the HtmlView class (you can init it in the constructor). But I think that's the limit I'm happy with.

avatar Fedik
Fedik - comment - 11 Jan 2020

I also not very like this approach, was a first idea I got :)

class property in the HtmlView

This not much helpful,
example in the fields layout it will not be available, or when layout rendered with LayoutHelper::render()

hm hm, need a class with shortkut methods ?

avatar wilsonge
wilsonge - comment - 11 Jan 2020

I mean in theory you can do the same class property in the layout class I guess. But feels a lot more grim - like layouts aren't really designed for this stuff.

avatar Fedik
Fedik - comment - 11 Jan 2020

yeap, then we have to do it in plugins, modules, that even worse :)

avatar wilsonge
wilsonge - comment - 11 Jan 2020

Dunno. But there's literally no point in having it in a JHtml helper. The intended goal for the container is to facilitate DI - not have more magic helpers :)

avatar wilsonge wilsonge - change - 11 Jan 2020
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2020-01-11 15:38:22
Closed_By wilsonge
Labels Added: ? ?
avatar wilsonge wilsonge - close - 11 Jan 2020
avatar Fedik
Fedik - comment - 11 Jan 2020

The intended goal for the container is to facilitate DI - not have more magic helpers :)

It not really about magic, more about make it shorter to work faster (some kind of proxy)
like in Laravel with helpers https://laravel.com/docs/5.8/helpers#method-url , I know exactly like this are not possible, but I like the idea

avatar HLeithner
HLeithner - comment - 11 Jan 2020

What george wanted to say is that the Factory should not be called in the future.

avatar mbabker
mbabker - comment - 11 Jan 2020

Laravel's global functions and facades are the equivalent in Joomla to Factory::getContainer()->get('foo')->doSomething(). The entire point of introducing a dependency injection system is to favor explicit dependencies over magical calls like HTMLHelper::_() or calls to global static/singleton resources like Factory::getFoo().

While Laravel's features might make a developer's life easier, they aren't necessarily an architecturally correct thing. You might as well stick to the 3.x API design if the use of dependency injection in Joomla is such a problem.

avatar Fedik
Fedik - comment - 12 Jan 2020

okay, we have 3 places where we often use an assets:

  • view
  • module
  • layout

(I ignore plugin, it different kind)

In view there already $this->document
In module can use $app->getDocument(), or can add one more variable $document
In layout we have nothing.

Do you think "injecting" Document instance in to FileLayout is a good idea?

Add a Comment

Login with GitHub to post a comment