TransWikia.com

Is it possible to create a component "addon"?

Joomla Asked by Chaosxmk on September 5, 2021

I’ve created a component for handling a multitude of things for my clients, but I frequently get feedback that certain sections aren’t needed or that additional sections are desired. The first solution that came to mind was to strip the component down to just core functions and create separate "addon" packages for installing each extra view.

Unfortunately, I’m not quite sure what I need to search for to figure out how to start something like this. The first/only thing I did find was documentation on how to update a component, but that feels a bit janky as a solution since each addon would need a copy of the core code and might make things a bit messy down the line.

One Answer

So, after having done some research and testing various things, I have an answer.

I created a spin-off of my component and stripped it down to the bare minimum. Every file that would theoretically already by included in the core was removed, only the controllers/models/tables/views were kept. Ex: (items prefixed with × were deleted)

/script.php
/administrator
    /controllers
×       /controlpanel.php
        /bulletin.php
        /bulletinlist.php
×   /css
        /general.css
    /models
×       /controlpanel.php
        /bulletin.php
        /bulletinlist.php
    /tables
        /bulletin.php
    /views
×       /controlpanel
        /bulletin
        /bulletinlist
    /controller.php
    /core.php
    /model.php
    /view.php
×/languages
    /administrator
        /en-GB
            /en-GB.com_component.ini
    /site
        /en-GB
            /en-GB.com_component.ini
/site
    /controllers
        /bulletin.php
        /bulletinlist.php
    /models
        /bulletin.php
        /bulletinlist.php
    /views
        /bulletin
        /bulletinlist
    /controller.php
    /core.php
    /model.php
    /router.php
    /view.php

In the manifest file for the installation, it's important to also trim this down to the needed content, and make sure that <extension> has the attribute method="upgrade", otherwise Joomla will cancel the install due to the component already existing.

Important things to note:

  • I've tried several different attempts, not once was I able to get the install package to run the install SQL file, I assume Joomla skips this step because this is technically an upgrade. Any SQL changes will need to be done directly in a script.php.
  • Any file that already exists will be overwritten, so for things like language files, you'll need to setup a jank solution in script.php to append new JText lines to the end of the installed language file
  • In the <administration> section of the manifest file, it's better to remove any reference to <menu> or <submenu>, I've noticed that it will erase whatever menu items existed already to replace them with the structure included in the upgrade

I don't have access to Joomla 4 at the moment to test if this will work there as well, but considering the wording in the Joomla documentation I don't see why it wouldn't work.

Update: After testing some more, I've noticed that any file that is in the root of a folder (/administrator or /site) will be deleted if not referenced in the manifest file. It looks like those files will have to be included even if they aren't different from the core files.

Answered by Chaosxmk on September 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP