? Pending

User tests: Successful: Unsuccessful:

avatar Fedik
Fedik
20 Oct 2018

This is update to #22435

Summary of Changes

Now the WebAssetRegistry shows a correct state of dependency, even before attach happen. So the asset state active/inactive should be correct at any time.

Also I have improved dependency calculation, to use Topological sorting.

Testing Instructions

Run somewhere:

$waInst = new \Joomla\CMS\WebAsset\WebAssetRegistry;
$waInst->setDispatcher($app->getDispatcher());
$waInst->addAsset(new \Joomla\CMS\WebAsset\WebAssetItem('mother'));
$waInst->addAsset(new \Joomla\CMS\WebAsset\WebAssetItem('father'));
$waInst->addAsset(new \Joomla\CMS\WebAsset\WebAssetItem('child1', ['dependencies' => ['mother', 'father']]));

$waInst->enableAsset('child1');

var_dump($waInst->getAsset('mother')->isActive());
var_dump($waInst->getAsset('father')->isActive());
var_dump($waInst->getAsset('child1')->isActive());

$waInst->enableAsset('mother');
$waInst->disableAsset('child1');

var_dump($waInst->getAsset('mother')->isActive());
var_dump($waInst->getAsset('father')->isActive());
var_dump($waInst->getAsset('child1')->isActive());

Expected result

true
true
true

true
false
false

Actual result

false
false
true

true
false
false

@mbabker one more review? 😉

ping @mbabker @wilsonge

Additional question:

Need to decide how to use assets in layouts and other parts of the CMS.

Current ways are:

Factory::getDocument()->getWebAssetManager()->enableAsset('fooBar');

Factory::getContainer()->get('webasset')->enableAsset('fooBar');

Factory::getContainer()->get('webasset') - does not depends from a request, and can be run at any time of execution, that I like
Factory::getDocument()->getWebAssetManager() - depends from request, and can be run only "afterRoute"

what could be better, any ideas? something "between" these two.

avatar Fedik Fedik - open - 20 Oct 2018
avatar Fedik Fedik - change - 20 Oct 2018
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 20 Oct 2018
Category Libraries
dc45476 20 Oct 2018 avatar Fedik phpcs
avatar Fedik Fedik - change - 20 Oct 2018
Labels Added: ?
avatar mbabker
mbabker - comment - 20 Oct 2018

Factory::getDocument()->getWebAssetManager() - depends from request, and can be run only "afterRoute"

Good. Plugins that are arbitrarily trying to load media in onAfterInitialise are problems anyway. Media loading shouldn't be allowed until we know the request format, the current API makes it way too easy to force HTML format if you are crazy enough to try a non-HTML outputting request.

avatar wilsonge wilsonge - change - 26 Oct 2018
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2018-10-26 09:41:19
Closed_By wilsonge
avatar wilsonge wilsonge - close - 26 Oct 2018
avatar wilsonge wilsonge - merge - 26 Oct 2018
avatar wilsonge
wilsonge - comment - 26 Oct 2018

Thanks!

Add a Comment

Login with GitHub to post a comment