User tests: Successful: Unsuccessful:
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?
Add info about this.
Status | New | ⇒ | Pending |
Category | ⇒ | Layout Libraries |
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
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.
yeap, then we have to do it in plugins, modules, that even worse :)
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 :)
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-01-11 15:38:22 |
Closed_By | ⇒ | wilsonge | |
Labels |
Added:
?
?
|
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
What george wanted to say is that the Factory should not be called in the future.
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.
okay, we have 3 places where we often use an assets:
(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?
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.