No Code Attached Yet
avatar zstergios
zstergios
18 Nov 2022

Joomla has great plugin system that allows you to manipulate the variables to able to re-route the result of page.
Seems not works on Joomla 4 and VM 4.

Steps to reproduce the issue

Create a plugin and place code at onAfterInitialise() event

$this->app->input->set('option','com_virtuemart');
$this->app->input->set('view','productdetails');
$this->app->input->set('virtuemart_product_id',1);

Expected result

All pages to load specific specific view

Actual result

Core variables option, view , task not manipulated!
Seems like stores in OBJECT the vars in the framework load

System information (as much as possible)

Setting Value
PHP Built On Linux server.linux91.papaki.gr 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
Database Type mysql
Database Version 10.3.37-MariaDB
Database Collation utf8_general_ci
Database Connection Collation utf8mb4_general_ci
Database Connection Encryption None
Database Server Supports Connection Encryption No
PHP Version 7.4.33
Web Server Apache
WebServer to PHP Interface cgi-fcgi
Joomla! Version Joomla! 4.2.5 Stable [ Uaminifu ] 8-November-2022 15:00 GMT
User Agent Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0

Additional comments

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar zstergios zstergios - open - 18 Nov 2022
avatar zstergios zstergios - change - 18 Nov 2022
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 18 Nov 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 18 Nov 2022
avatar zstergios zstergios - change - 18 Nov 2022
The description was changed
avatar zstergios zstergios - edited - 18 Nov 2022
avatar zstergios zstergios - change - 18 Nov 2022
The description was changed
avatar zstergios zstergios - edited - 18 Nov 2022
avatar zstergios zstergios - change - 18 Nov 2022
Title
Manipulating vars from onAfterInitialise()
Manipulating vars in onAfterInitialise()
avatar zstergios zstergios - edited - 18 Nov 2022
avatar joomdonation
joomdonation - comment - 18 Nov 2022

Shouldn't you use onAfterRoute instead ?

avatar zstergios
zstergios - comment - 18 Nov 2022

onAfterInitialise() is called before onAfterRoute().

The onAfterRoute has already loaded the non-desired view/component


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39235.

avatar joomdonation
joomdonation - comment - 18 Nov 2022

I don't know how onAfterRoute has already loaded the non-desired view/component. On my quick test, I used the code like this:

public function onAfterRoute()
{
	if ($this->app->isClient('site'))
	{
		$this->app->input->set('option', 'com_contact');
		$this->app->input->set('view', 'category');
		$this->app->input->set('id', 4);
		$this->app->input->set('layout', 'default');
	}

}

And that loads category view of category with ID = 4 in com_contact. So onAfterRoute() works well for me. I can use that event to route to the component/view I want.

avatar zstergios
zstergios - comment - 18 Nov 2022

On Joomla 1.5 up to 3.x the onAfterInitialise() worked for me.

I don't know if has any issue the specific component I am trying (virtuemart)

I will do my tests and I will come back with the results


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39235.
avatar joomdonation
joomdonation - comment - 18 Nov 2022

I will have to check it again but I remember I read somewhere that in Joomla 3, Joomla Input object use $_REQUEST as reference, so any modification to Joomla input object will affect data from $_REQUEST.

On Joomla 4, $_REQUEST is not passed by reference to input object anymore, so modify Joomla input object won't make change to $_REQUEST.

With that said, if VM for some reasons, uses data from $_REQUEST instead of using data from Joomla input object, the change won't have any affect.

(Haven't looed at VM from long time ago, so I can just guess)

As for modify routing variables like in this example, I believe onAfterRoute is the right event to use.

Hope you will figure out and come up with a solution.

avatar joomdonation joomdonation - close - 29 Nov 2022
avatar joomdonation
joomdonation - comment - 29 Nov 2022

Closing because this is a none core issue. Feel free to re-open if you have something want to discuss further.

avatar joomdonation joomdonation - change - 29 Nov 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-11-29 07:25:19
Closed_By joomdonation

Add a Comment

Login with GitHub to post a comment