Add-on development MODX 2.3+ and 3+ --> single package or separate versions?


I’m just starting to make the GoodNews add-on MODX 3 proof! As there are a lot of changes under the hood, I’m not sure if it’s not better to create two different versions of the package. One for MODX 2.3+ and one for MODX 3+.

How does other developers handle this?


It’s a great question. I haven’t looked at this much. Most of my extras ran OK in 3.0 when I tested them, though that was at least a year ago.

My inclination would be to use a single version that either works on both versions of MODX or checks the version number and behaves accordingly whenever possible.

Whenever I’ve created multiple versions of something, I’ve been sorry. There are always changes that need to be applied to both packages. There’s something really annoying (to me at least) about having to make the same changes twice (changing the code, changing the version number, updating the changelog, uploading, describing and releasing the new version, etc.). YMMV.

1 Like

That seems to be a bigger problem as even the file/ folder structure has changed massively and include commands are failing. Also it seems that MODX 3 requires your add-on using PHP namespace.

I will probably handle the file location changes with variables set early on the basis of the MODX version. I don’t think introducing namespaces will harm the backward compatibility, and it may be possible to use them to handle the path changes.

PHP namespaces aren’t required in your own code - but useful to have.

So far the extras I’ve tested and developed against 3.0-alpha2 have been fairly easy to get cross compatible. Mostly things that were strictly checking variable types (e.g. $resource instanceof modResource) needed fixing. Couple of things that could be resolved with a class_alias call.

Unfortunately it’s more complicated for custom resource types. For a little while I thought I accomplished cross compatibility in moregallery, but while the resource class worked fine in 2.7 and 3.0, it no longer showed up as an option in the resource types dropdown. Haven’t figured that out yet, so that might require duplicated code or even separate versions.

1 Like

Making GoodNews MODX 3 compatible, will probably be a headache…

@markh What’s the fix for instanceof?

I have a PR for MIGX here from crystaldaking:

it doesn’t look like this could be made cross compatible

Loosening up the check to only if ($resource), doing a conditional instanceof for both 2.x and 3.x class names, or adding a class_alias so they’re one and the same.

Can you give an example of a class alias?

Create a separate version. It will probably be much easier on you.

I shared a sample class on github to test for MODX version and PHP version for MODX3 apps.

This one?

Create seperate git repos or only seperate branches, then?
I’ve no idea, how to handle that to keep both versions in sync.
Is that even possible?