[ENHANCEMENT]: Missing places for class headers #1145
Labels
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: joomla/Component-Builder#1145
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Enhancement Details
Hey,
I noticed a few places were it's not possible to add class headers. For some of them it's possible to find workarounds but for some others it's not.
Here are the places I found so far :
Cheers ;-)
Which part of the extension will be affected by this enhancement?
No response
Additional Context
No response
It is actually possible to add class headers everywhere. In fact, the current plugin that allows you to customly and manually target class headers in different views is obsolete and will be phased out when transitioning to Joomla 6. The new approach is what is called Super Power or Joomla Power Inclusion. These are two concepts that we will explore in depth at our next JUG meeting. I have already mentioned them in the past, but perhaps people have not fully understood their capabilities. This feature will automatically add your class headers anywhere in any area. All you need to do is use the SPK key in your custom code where you want the class name to appear.
Implementation of the SPK Key
In any place within your custom code where the class name should appear, you add the SPK key. For instance, if your class needs to be instantiated, you will use the keyword
new
followed by the SPK key as the class name.This will result into:
Here's what happens:
use
statement to the head of the file.use
statement to avoid any collision.This process is done per file, ensuring that each SPK placeholder is updated correctly every time. In fact, JCB already uses this intensively across the core of the application, and it has been working quite well since we moved to Joomla 5.
Use in Install Scripts
Using the SPK key in your custom code is the way to get the headers added to:
A little note about the install script: We've recently added a feature to the install script for Joomla 3, 4, and 5, which allows you to check whether the class is available. If the class is not available, it will trigger the built-in autoloader for the Joomla powers, then check if the class is available after that, and return true or false.
Here is the code to add the schema checker to any project:
This is how it looks in JCB:
![image](https://git.vdm.dev/attachments/cd74e30f-6bc8-4fc5-9195-307ea070773d)
You need do nothing more, since after adding that code to JCB, it will auto detect these classes (search for them) add them to you that system (if they where not found in the database), add then to the Joomla Package and update all files as needed.
Be sure to use the latest package: https://git.vdm.dev/joomla/pkg-component-builder/archive/v3.2.2-beta2.zip (BETA-2)
This also works for the new Joomla Powers area, the stable version of that is part of the next release. Here is the repo with the docs. Please read over it, and give it a try... gone is the days, of struggling to keep up with the changes in Joomla, we can now per Joomla version drop in the new namespaces. With much more to come.
Demonstration
This is part of the demonstration that we plan to do in the next JUG meeting. I will provide more details during that demonstration on exactly how this is done. In short, this feature is already possible and quite powerful.
@Llewellyn I know it's not the place, but can you tell me more about the JUG, you are talking about...?
Where and when and how to access it...
Thanks
See https://joomlacommunity.cloud.mattermost.com/main/channels/jcb for more details ;)
Thanks for this extensive answer Llewellyn. I understand now what I can achieve with super powers. It solves 95% of my issue.
The only remaining problem is how to use my component helper class in a post-install method ?
The following will only work for Joomla 4+ (components) and build with:
The easiest way would be for the ADMINISTRATOR helper (in the install script):
The easiest way would be for the SITE helper (in the install script):
This will add the component helper class to the head of the file, and allow you to call it. I have not tested this on a new install yet... let me know.