No Code Attached Yet
avatar mavrosxristoforos
mavrosxristoforos
16 Nov 2020

Steps to reproduce the issue

Install any system plugin (or edit an existing one to test it) and write (or modify an existing onAfterRoute() function)

  public function onAfterRoute() {
    JHtml::_('jquery.framework');
  }

Expected result

jQuery added in document scripts.

Actual result

Error: 0 Call to a member function getWebAssetManager() on null
Location: JROOT\libraries\src\HTML\Helpers\Jquery.php:48

System information (as much as possible)

Joomla 4 Beta 5
PHP 7.2.10

Additional comments

I believe that the PHP version is irrelevant, as well as any other system information.
This occurs at JROOT\libraries\src\HTML\Helpers\Jquery.php, line 48

46:  public static function framework($noConflict = true, $debug = null, $migrate = false)
47:  {
48:    $wa = Factory::getApplication()->getDocument()->getWebAssetManager();

The document property of the Application object is null.
Same happens both in the front-end (SiteApplication) and the back-end (AdministratorApplication).
Maybe it's not supposed to work at that point anyway, but it worked on Joomla 3, so I thought I should mention it.

avatar mavrosxristoforos mavrosxristoforos - open - 16 Nov 2020
avatar joomla-cms-bot joomla-cms-bot - labeled - 16 Nov 2020
avatar Fedik
Fedik - comment - 16 Nov 2020

hmhm, that because Document not exists in Application until dispatch happen

public function dispatch($component = null)
{
// Get the component if not set.
if (!$component)
{
$component = $this->input->getCmd('option', null);
}
// Load the document to the API
$this->loadDocument();
// Set up the params

I would suggest just move your JHtml::_('jquery.framework'); to onAfterDispatch event

avatar joeforjoomla
joeforjoomla - comment - 16 Nov 2020

@Fedik yes that's the reason, but this issue could potentially break several sites, it would be ideal to provide a legacy way to have it working.

avatar mavrosxristoforos
mavrosxristoforos - comment - 16 Nov 2020

@Fedik Yes, I tried that and it seems to work. Also onBeforeCompileHead(). However, I thought it was worth mentioning somewhere, because it worked differently on Joomla 3.

@joeforjoomla I agree.

avatar joomdonation joomdonation - change - 12 Nov 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-11-12 15:00:56
Closed_By joomdonation
Labels Added: No Code Attached Yet
Removed: ?
avatar joomdonation joomdonation - close - 12 Nov 2022
avatar joomdonation
joomdonation - comment - 12 Nov 2022

Closing this issue because the user who reported this issue had solution for this problem. Anyone has similar issue, please look at @Fedik answer above #31415 (comment)

Add a Comment

Login with GitHub to post a comment