Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions administrator/modules/mod_login/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;

HTMLHelper::_('behavior.core');
HTMLHelper::_('behavior.formvalidator');
HTMLHelper::_('behavior.keepalive');
HTMLHelper::_('script', 'system/fields/passwordview.min.js', ['version' => 'auto', 'relative' => true]);
HTMLHelper::_('script', 'mod_login/admin-login.min.js', ['version' => 'auto', 'relative' => true]);
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $app->getDocument()->getWebAssetManager();

// Allow template to provide its own asset for the module
if (!$wa->assetExists('script', 'mod_login.admin'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the advantage of this vs a regular template override?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular template override will override by path, but cannot overide asset by name for modules, because the module will be rendered after index.php of template (I mean template assets loaded before any module).
And example in current case mod_login will replace 'mod_login.admin' to its own (even if the template provide it also).

With suggested changes if template provide 'mod_login.admin' then it will be used instead of one provided by "module"

I found this issue while doing changes for a modules.

I also thinking about something like registerIfNotExists() but not sure currently. For now made extra if() check in modules.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But surely that's only useful for presets rather than singular assets like this where we have a single resource? I don't see the benefit here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want allow to template to override asset by "asset name".
To be consistent. Because it possible for components, and not really for modules, because they "goes after" template.

But I can revert such part, not much critical issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let's revert for now please

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reverted,

{
$wa->registerScript('mod_login.admin', 'mod_login/admin-login.min.js', [], ['defer' => true], ['core', 'form.validate']);
}

$wa->useScript('core')
->useScript('form.validate')
->useScript('keepalive')
->useScript('field.passwordview')
->useScript('mod_login.admin');

Text::script('JSHOWPASSWORD');
Text::script('JHIDEPASSWORD');
Expand Down
5 changes: 3 additions & 2 deletions administrator/modules/mod_multilangstatus/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;

HTMLHelper::_('bootstrap.framework');
HTMLHelper::_('script', 'mod_multilangstatus/admin-multilangstatus.min.js', array('version' => 'auto', 'relative' => true));
$app->getDocument()->getWebAssetManager()
->registerAndUseScript('mod_multilangstatus.admin', 'mod_multilangstatus/admin-multilangstatus.min.js', [], ['defer' => true]);

?>

<div class="header-item-content multilanguage">
Expand Down
11 changes: 10 additions & 1 deletion administrator/modules/mod_quickicon/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;

HTMLHelper::_('script', 'mod_quickicon/quickicon.min.js', ['version' => 'auto', 'relative' => true]);
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $app->getDocument()->getWebAssetManager();

// Allow template to provide its own asset for the module
if (!$wa->assetExists('script', 'mod_quickicon'))
{
$wa->registerScript('mod_quickicon', 'mod_quickicon/quickicon.min.js', [], ['defer' => true]);
}

$wa->useScript('mod_quickicon');

$html = HTMLHelper::_('icons.buttons', $buttons);
?>
Expand Down
6 changes: 2 additions & 4 deletions administrator/modules/mod_sampledata/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;

HTMLHelper::_('bootstrap.framework');
HTMLHelper::_('form.csrf');
HTMLHelper::_('script', 'mod_sampledata/sampledata-process.js', ['version' => 'auto', 'relative' => true]);
$app->getDocument()->getWebAssetManager()
->registerAndUseScript('mod_sampledata', 'mod_sampledata/sampledata-process.js', [], ['defer' => true], ['core']);

Text::script('MOD_SAMPLEDATA_CONFIRM_START');
Text::script('MOD_SAMPLEDATA_ITEM_ALREADY_PROCESSED');
Expand Down
11 changes: 11 additions & 0 deletions build/media_source/system/joomla.asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@
"dragula"
]
},
{
"name": "field.passwordview",
"type": "script",
"uri": "system/fields/passwordview.min.js",
"attributes": {
"defer": true
},
"dependencies": [
"core"
]
},
{
"name": "webcomponent.field-fancy-select",
"type": "script",
Expand Down
8 changes: 3 additions & 5 deletions components/com_finder/tmpl/search/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;

HTMLHelper::_('behavior.core');

Text::script('MOD_FINDER_SEARCH_VALUE', true);

HTMLHelper::_('stylesheet', 'com_finder/finder.css', array('version' => 'auto', 'relative' => true));
HTMLHelper::_('script', 'com_finder/finder.js', array('version' => 'auto', 'relative' => true));
$this->document->getWebAssetManager()
->registerAndUseStyle('com_finder', 'com_finder/finder.css')
->registerAndUseScript('com_finder', 'com_finder/finder.js', [], ['defer' => true], ['core']);

?>
<div class="com-finder finder">
Expand Down
4 changes: 2 additions & 2 deletions components/com_wrapper/tmpl/wrapper/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;

HTMLHelper::_('script', 'com_wrapper/iframe-height.min.js', array('version' => 'auto', 'relative' => true));
$this->document->getWebAssetManager()
->registerAndUseScript('com_wrapper.iframe', 'com_wrapper/iframe-height.min.js', [], ['defer' => true]);

?>
<div class="com-wrapper contentpane">
Expand Down
13 changes: 11 additions & 2 deletions modules/mod_finder/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@
$output .= $input;
}

HTMLHelper::_('script', 'com_finder/finder.js', array('version' => 'auto', 'relative' => true));
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $app->getDocument()->getWebAssetManager();

// Allow template to provide its own asset for the module
if (!$wa->assetExists('script', 'com_finder'))
{
$wa->registerScript('com_finder', 'com_finder/finder.js', [], ['defer' => true]);
}

$wa->useScript('com_finder');

Text::script('MOD_FINDER_SEARCH_VALUE', true);

Expand All @@ -52,7 +61,7 @@
*/
if ($params->get('show_autosuggest', 1))
{
$app->getDocument()->getWebAssetManager()->usePreset('awesomplete');
$wa->usePreset('awesomplete');
$app->getDocument()->addScriptOptions('finder-search', array('url' => Route::_('index.php?option=com_finder&task=suggestions.suggest&format=json&tmpl=component')));
}
?>
Expand Down
11 changes: 10 additions & 1 deletion modules/mod_languages/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Uri\Uri;

HTMLHelper::_('stylesheet', 'mod_languages/template.css', array('version' => 'auto', 'relative' => true));
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $app->getDocument()->getWebAssetManager();

// Allow template to provide its own asset for the module
if (!$wa->assetExists('style', 'mod_languages'))
{
$wa->registerStyle('mod_languages', 'mod_languages/template.css');
}

$wa->useStyle('mod_languages');

?>
<div class="mod-languages">
Expand Down
7 changes: 4 additions & 3 deletions modules/mod_login/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;

HTMLHelper::_('behavior.core');
HTMLHelper::_('behavior.keepalive');
HTMLHelper::_('script', 'system/fields/passwordview.min.js', array('version' => 'auto', 'relative' => true));
$app->getDocument()->getWebAssetManager()
->useScript('core')
->useScript('keepalive')
->useScript('field.passwordview');

Text::script('JSHOWPASSWORD');
Text::script('JHIDEPASSWORD');
Expand Down
12 changes: 10 additions & 2 deletions modules/mod_menu/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
defined('_JEXEC') or die;

use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\HTML\HTMLHelper;

HTMLHelper::_('script', 'mod_menu/menu.min.js', array('version' => 'auto', 'relative' => true));
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $app->getDocument()->getWebAssetManager();

// Allow template to provide its own asset for the module
if (!$wa->assetExists('script', 'mod_menu'))
{
$wa->registerScript('mod_menu', 'mod_menu/menu.min.js', [], ['defer' => true]);
}

$wa->useScript('mod_menu');

$id = '';

Expand Down
13 changes: 11 additions & 2 deletions modules/mod_wrapper/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;

HTMLHelper::_('script', 'com_wrapper/iframe-height.min.js', array('version' => 'auto', 'relative' => true));
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $app->getDocument()->getWebAssetManager();

// Allow template to provide its own asset for the module
if (!$wa->assetExists('script', 'com_wrapper.iframe'))
{
$wa->registerScript('com_wrapper.iframe', 'com_wrapper/iframe-height.min.js', [], ['defer' => true]);
}

$wa->useScript('com_wrapper.iframe');

?>
<iframe <?php echo $load; ?>
id="blockrandom-<?php echo $id; ?>"
Expand Down