Closed SharkyKZ closed 1 year ago
The view one should be removed so the API acts the same way as the web view controller and system plugins can do any manipulation of the document. I know there aren’t any system plug-in calls in the application at the moment but the PR has been pending for years :) https://github.com/joomla/joomla-cms/pull/34151/files
Since october Allon is awaiting your feedback within that PR ;)
He wants to remove the system plugins from it. Which is specifically the important part for this issue :)
The view one should be removed so the API acts the same way as the web view controller and system plugins can do any manipulation of the document. I know there aren’t any system plug-in calls in the application at the moment but the PR has been pending for years :) https://github.com/joomla/joomla-cms/pull/34151/files
That would be another step back. Going forward, the CMS should be modeled more like the framework where things actually make some sense. Even if the document concept remains, its creation should be pushed up into the controller. The application has no clue what document is needed or if it's needed at all. It's not needed at all on redirect pages, for example, and only the controller is aware of such context.
As for your PR, it can be closed as it makes no sense. It's clearly modeled after the fundamentally broken offline handling in the site application. Why would you prevent rendering the page but still allow users to make CRUD operations? Likewise, in site application users without offline login permissions can actually login and perform these operations by making direct POST requests. And the offline login screen is shown only on HTML pages. Other document types are not affected at all.
Ultimately, offline check needs to be performed early on, before the dispatch step. Near the MFA and password reset handling.
That would be another step back. Going forward, the CMS should be modeled more like the framework where things actually make some sense. Even if the document concept remains, its creation should be pushed up into the controller. The application has no clue what document is needed or if it's needed at all. It's not needed at all on redirect pages, for example, and only the controller is aware of such context.
No that's never going to be the case because both plugins and modules can e.g. add scripts to the DOM which need a document. The fact is there's more than just controllers in the Joomla Ecosystem - so it's the applications job to have a document that is format aware (e.g. feed views differentiated from html views) or json api from json ld formats. I accept it's not needed on every page - but frankly your at the controller level before you realise that - but a bunch of plugins have already run and potentially added scripts to the page (e.g. articles anywhere etc). Doing anything like that is incredibly shortsighted for the extension ecosystem.
but a bunch of plugins have already run and potentially added scripts to the page
Something like this should only happen in poorly written plugins that create the document before the application does it, i.e. by calling Joomla\CMS\Factory::getDocument()
during onAfterRoute
or earlier event. These are already causing issues in J4 (and actually have been causing issues in J3, if not before that) anyways, but the method is deprecated so this shouldn't be a problem in the future. The earliest events where plugins can safely access the document are the events dispatched by the component itself anyways.
Modules are rendered by the document itself, so nothing changes for them.
so it's the applications job to have a document that is format aware
It's how it is now but it doesn't have to be. In the long term Joomla\CMS\Application\CMSWebApplicationInterface::getDocument()
should be removed. Document class is very much like Joomla's equivalent of a renderer. It should exist only during the lifetime of a component. Plugins could still hook into it before it's rendered and during transition period the application's document object could be seeded.
What needs to be fixed
The document in the API application is rendered twice. First the document is rendered by the view but the result is not used:
Later the document is rendered in
Joomla\CMS\Application\ApiApplication::render()
when it's called inside theJoomla\CMS\Application\CMSApplication::execute()
:Why this should be fixed
Just.
How would you fix it
Remove one instance of render call. Preferably the one in the application.
Side Effects expected
Yes.