Powers not compiled and not implemented in class header #997
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: joomla/Component-Builder#997
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
Steps to reproduce the issue
Expected result
3 problems occur:



Problem 1: Power is not even compiled:
Problem 2: Use is not implemented in the controller
Problem 3: even when you manually create the class and add it to the use list, its not actually loaded
Manually loading it using require_once does load the file:

Actual result
System information (as much as possible)
Additional comments
I have asked multiple other programmers about the class not loading when it is defined in the use lines, and nobody managed to figure it out. It should just autoload but it just doesn't.
Okay chrome browser is a no go, it is to much involved with the local system. Please use Firefox.
Then please make sure you have the plugin enabled:

And you have the plugin linked:

Their is another way to no link powers, and I am planing to push out some tutorials surrounding that soon. But in short you need to use the SPK value, in place of the class name in your code once.

Like this:
This will auto load powers from V3.1.24
But the old way of direct linking should still work, and is still my main mode of using powers as it is faster, and more stable.
I see you have it set to
Based on Component
so is the component set to load powers? and what happens if you change it toAlways
.I tested this:

Saved and compiled, and the result was:

What that tells me, if all your settings in JCB is correct, and your in the right browser and it still fails, then there is a system issue.
Having said that, I don't mean to imply that I am unwilling to fix it. Rather, I simply can't without more details, as I need to be able to replicate the issue. In the industry, we attempt to unify the environment by using a container.
Utilizing a container ensures that we all operate in the same environment. This is why I built Octojoom. In this way, we are all in the same environment, enabling us to debug and observe the same phenomena most effectively.
Given that we are only two core developers on JCB at this time, targeting more diverse environments is currently unfeasible. Therefore, to ensure that your PHP setup matches ours, check the docker file, and observe all the steps it takes in preparing the container. You will see here all the modules and other necessary components that must be installed to guarantee we have the same environment. The Joomla docker container is intended to be the optimal way to run Joomla, and so JCB is simply following that as a baseline.
However, I am not suggesting that there is no way to get JCB to run in other environments. I am merely stating that I can't be the one to make it happen. I transitioned entirely to Ubuntu in 2010 (I believe), and I have never looked back. As a programmer, I can confidently say that I have found my home. If I were a desktop developer, this would not be ideal, as most people use Windows.
But since I am a cloud developer, the landscape is quite different. The server market is heavily dominated by Linux, with a significant majority of cloud systems running on Linux-based operating systems. While the exact figure varies, it's safe to say that between 89% and 98% of all cloud systems are Linux-based, reflecting the robustness, security, and flexibility of Linux in handling server tasks. This means I am now operating in the environment of my end product. For this reason, I don't see the wisdom in reverting to Windows.
You mentioned that you've consulted other programmers. I would encourage you to invite them to participate in this discussion as well. Why should any conversation about issues in the JCB core be held privately?
We need more developers actively contributing to JCB.
This includes responding to issues, testing beta version releases, participating in discussions, and essentially sharing their perspectives. If more than one programmer is experiencing this issue, they should all comment on this issue with their findings and screenshots. This collective input will help me resolve the issue more quickly. A community is not comprised of two core developers and the rest as users; rather, it means that everyone is a contributor.
Thanks for the quick response! I checked:
One plugins was not activated, and now the use class is properly added! problem 1 & 2 fixed!
All compiling is done in Firefox
Sorry for the incoming image spam btw, i find it easier to explain with images than just text
Now i have found something i don't understand:


Attempting to use the class in the postSaveHook works great
But when i attempt the same thing in the custom buttons area


The button shows up but the class is not loaded
Dumping the get_loaded_classes() function shows that when the postSaveHook is called, 437 classes are loaded while in the controller 'only' 365 are. When dumping get_loaded_classes() in the postsavehook shows that these classes are loaded

While if you dump get_loaded_classes() in the controller function it is missing all these classes. Could this be a hint to where this goes wrong?
I accidentally closed it, sorry about that. If you want me to show this issue you can always shoot me a message on telegram
Hmm I am not sure I follow all your saying... so in reflection this is what I understood. Your adding the class via the Class Headers tab, and this works now.
Then using this class in the custom code works if your using the
postSaveHook
method, but not if you directly add a new function to the controller, via the Custom Buttons tab.So this is where you lose me... if the Class is loaded to the head of the controller file via the Class Headers tab, it means the class is loaded to the powers area, and linked via the
use
statement at the top of the file.This means no matter where your trying to use the class in the file it should work, unless its no longer loaded to the head of the file, in which case that is the issue, and no the where the class is used.
Remember there are two controllers per view, the controller for the list view and the controller for the edit view. Make sure that your targeting the correct file in all instances.
By the way the
postSaveHook
is found in the edit view controller, and the first controller block in the Custom Buttons tab, is targeting the edit view controller.By the way you don not need to actually add a button to add methods into these areas. Just adding code will still work.
So I tested what I understood, and it works:
Add the power:

Use the power:

And this works perfectly.... but again if targeted by a list view button, we must use the controllers (list view) area, and if by an edit view me must use the first controller for the edit view.
Just to test i have added my headertest class to all options in the 'class headers' tab.

Next i tried all combinations of the target (single/both/list) and the type (default/selection/function) in the custom buttons to see if that changed something, sadly it didn't. I went looking some more into why there are more classes loaded when the
postSaveHook
is triggered and found something that might explain it.The spl_autoload_register that registers the component namespace is loaded in the
DemoHelper
class, which is not loaded when you're calling the test function in the controller.It is possible to just add random strings in the use list at the start of the file for example:

This throws no error. so only adding the use to the list is not enough for it to actually attempt to load the namespaces. Copy pasting the autoloader from the DemoHelper into the controller loads the Headertest class without issue. My conclusion (and please correct me if i'm wrong here):
The class
DemoControllerLook
extends theFormController
circumventing the loading of theDemoHelper
class. Since theFormController
is a extension of theBaseController
the actual component (and thus the component namespace) is not loaded.Again i could be completely wrong here, i still don't know why you can just add a bunch of nonsense
use
lines and no errors occur.Okay I am not sure what your trying to do... but what ever it is, you lost me.
Simple truth is that the helper class loads with every component call that looks like this
?option=com_componentname
since this triggers the entry point file that always loads the helper class.That said if your trying to trigger your component from another component you will need to use the Power (Load by plugin) approach.
I don't think I can help you any further... as JCB is not the issue here. JCB does what it should do.
Obviously adding nonsense stuff will break things.
As a second test i went into the JCB admin views controller and put a dump of get_declared_classes() in the
runExpansion
function called from the run expansion button in the admin_views view. and compared it between that and the dump of the get_declared_classes() of the demo list view controller. Turns out that the JCBComponentbuilderControllerAdmin_views
controller loads 4 extra classes compared to theDemoControllerLooks
. One of those 4 extra classes is theComponentbuilderHelper
class. Exactly the class that has the autoload for the namespace. I am starting to having trouble wrapping my head around how this all works but from what i'm getting the general helper file jcb generates is not loaded everywhere in the components it builds.I have no idea what your doing... since none of it makes sense. I have never needed to any of this, and all my extensions work.
You have not confirmed your system has all the needed PHP modules set... I really do not understand what your saying.
I load hundreds of classes all over the system and do not have any of these issues you speak about... not that I actually understand what your saying.
The only conclusion I have is that your not matching this correctly and that is it.
I have demonstrated that this feature is stable and works as expected. Maybe its time for you to make a detailed video of what your doing... from beginning to end, not skipping any part. Without fully understanding what your really doing I am wasting my time.