J4 Issue ?
avatar frogydiak
frogydiak
28 Jul 2018

Steps to reproduce the issue

An issue with my custom component I am developing from scratch with 4.0 new ways of loading classes. I am following how com_acrticle, com_banner, and com_contact was created and how it loads classes via the Service folder. So, I created my own libraries of classes and it is loading automatically just fine using name classes anywhere I call it until I noticed Text class does not work anymore in my custom component classes unless my custom class extends Joomla's classes like HTMLView. This issue started when I first experienced and reported an issue with frontpage not loading a class #21177.

Prior to that, Text is working just fine. I guess this is related to the new class autoloader.

avatar frogydiak frogydiak - open - 28 Jul 2018
avatar joomla-cms-bot joomla-cms-bot - change - 28 Jul 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 28 Jul 2018
avatar mbabker
mbabker - comment - 29 Jul 2018

Have you verified the language file(s) in question are actually loaded?
There is nothing in the language API autoloading anything but overrides and
the default language file, extension files still require manual loading.

On Sat, Jul 28, 2018 at 6:13 PM FrogyDiak notifications@github.com wrote:

Steps to reproduce the issue

An issue with my custom component I am developing from scratch with 4.0
new ways of loading classes. I am following how com_acrticle, com_banner,
and com_contact was created and how it loads classes via the Service
folder. So, I created my own libraries of classes and it is loading
automatically just fine using name classes anywhere I call it until I
noticed Text class does not work anymore in my custom component classes
unless my custom class extends Joomla's classes like HTMLView. This issue
started when I first experienced and reported an issue with frontpage not
loading a class #21177 #21177
.

Prior to that, Text is working just fine. I guess this is related to the
new class autoloader.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#21289, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAWfod8FjXowYDDQhYmFjb6wcTrBWLeGks5uLPAGgaJpZM4VlN13
.

--

  • Michael Please pardon any errors, this message was sent from my iPhone.
avatar franz-wohlkoenig franz-wohlkoenig - change - 29 Jul 2018
Status New Information Required
avatar franz-wohlkoenig franz-wohlkoenig - change - 29 Jul 2018
Category Code style
avatar frogydiak
frogydiak - comment - 30 Jul 2018

@mbabker Yes, I actually did verify that the language .ini file is loaded by enabling the language debug and the language translate text exists and loaded and there's no reported error on my ini file. Strange thing is, Text only work fin in HtmlView where it extends Joomla\CMS\MVC\View\HtmlView.

avatar brianteeman brianteeman - change - 30 Jul 2018
Labels Added: J4 Issue
avatar brianteeman brianteeman - labeled - 30 Jul 2018
avatar mbabker
mbabker - comment - 30 Jul 2018

Text only work fin in HtmlView where it extends Joomla\CMS\MVC\View\HtmlView

Nothing in the view classes is language aware (as in loading language files, having a property based on the language API, etc.). Without seeing some very explicit code examples and knowing your expectations, there's nothing really for us to debug.

avatar frogydiak frogydiak - change - 3 Aug 2018
Title
[4.0] Text Class Seems to be now working with custom component custom classes
[4.0] Text Class Seems to be not working with custom component custom classes
avatar frogydiak frogydiak - edited - 3 Aug 2018
avatar frogydiak
frogydiak - comment - 3 Aug 2018

Hmmm... well as a work around, what I did is load the component language in my custom class __contruct. I don't know the proper way of doing it in J4, I just thought it is auto loaded. I guess I have to wait for the documentation. The core components does not really explain much why and how things are working which is my pattern. I'm no PhP expert and still trying to learn. Thanks!

avatar mbabker
mbabker - comment - 3 Aug 2018

Again, without knowing exactly what it is you're trying to accomplish it's hard to say what your specific issue is.

In the context of a normal request cycle, component language files are loaded when a component dispatcher is created in 4.0, in 3.x it was when ComponentHelper::renderComponent() was called. So language files aren't loaded if you're randomly calling a class in your extension package from anywhere in the system (say a module or plugin using a helper class in your component), and we don't have a system that automatically loads in language files.

So your "workaround" might be the right solution for your specific "issue", or there very well may be some kind of bug somewhere. Again, it's hard to say because we really don't know what it is you're doing. If your component is the active component of the request cycle, its language files will be loaded (but if you're trying to use a class before that happens, say in a plugin subscribed to onAfterInitialise or onAfterRoute, at that point the language files won't be loaded because Joomla hasn't reached the point to load them yet). If it's not the active component for a request and you're trying to use a class, then the language files need to be manually loaded.

avatar frogydiak
frogydiak - comment - 7 Aug 2018

@mbabker Thank you for your explanation. Quick question, if I am currently on my custom component and I have created a Service class and I know it is loaded since I can see the class if I look at the service container.

On that service class, the Text object should be working properly, right?

I enabled the language debug and I know that my custom component language ini file is loaded and without error. But yet, Text is not translating the language.

I am not in a plugin or a module but rather I am in a component view which is calling a service class.

avatar mbabker
mbabker - comment - 7 Aug 2018

Is the language file loaded before or after the use in the service class? Debug might say it was loaded, but if it was loaded after you tried using it, that wouldn't help much.

The Text class is just a fancy static wrapper around the global Language object. It doesn't behave any differently based on where in the API you use it. Its only requirement is that Factory::getLanguage() gives you a Language object. So with that established, what is the state of the global Language object when you're trying to use your language string(s)? Has the component language file actually been loaded at the time of use? The debug output is going to tell you what's loaded over the course of the request cycle, it's not telling you when that load happens.

avatar mbabker
mbabker - comment - 8 Aug 2018

This is only very loosely updated to not have a broken display with the 4.0 UI changes, but install it and it'll give you some extra debug data about the loaded language files in the debug console (@laoneo @wilsonge we really need a factory for Language class instantiation so this plugs in a bit more easily and some kind of early system hook that can hook the container even before we start executing the application, because if you look how this plugin actually runs right now it's re-instantiating the Language class because we lack a factory service or early system hook to overload a factory service).

langdebug.zip

avatar frogydiak
frogydiak - comment - 10 Aug 2018

@mbabker Yes! you're right, my custom component language is not loaded on the service class at the time Text is called.

I was assuming that language is magically loaded by Joomla framework anywhere in the component. So, I tested it in com_content service class (icon) and it's language ini is not loaded as well at the time icon object calls Text. So I guess it is by design, unless that was an unforeseen behavior. Quick question, where or how does HtmlView class magically load a component language? I can't find it!

Anyways, I tried loading the language in the service provider class and that seems to work. Now I don't have to load the component language in every service object when I need to use Text.

Thank you for the language debug plugin, it is a helpful tool indeed. It should be added to the core IMO.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 10 Aug 2018

@frogydiak if the Issue is solved please close it, thanks.

avatar frogydiak frogydiak - change - 10 Aug 2018
Status Information Required Closed
Closed_Date 0000-00-00 00:00:00 2018-08-10 18:39:52
Closed_By frogydiak
avatar frogydiak frogydiak - close - 10 Aug 2018
avatar wilsonge
wilsonge - comment - 10 Aug 2018

Quick question, where or how does HtmlView class magically load a component language? I can't find it!

When you boot the component initially - it's not in the view at all :) Specifically in the components' dispatcher https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Dispatcher/LegacyDispatcher.php#L88

avatar frogydiak
frogydiak - comment - 11 Aug 2018

@wilsonge Awesome! Thank you!

Add a Comment

Login with GitHub to post a comment