Joomla 4 – How to use namespace in a third party module.

1,120 views
Skip to first unread message

Astrid Günther

unread,
Dec 20, 2018, 4:19:28 PM12/20/18
to Joomla! General Development

Hello


I just had a look to the j4 modules. For example breadcrumbs has a helper class in a namespace
namespace Joomla\Module\Breadcrumbs\Site\Helper;



I want to adapt this to may own module. But it did not work, because the namespace of my module is not not mapped in the file

/libraries/autoload_psr4.php

Is there a recommended way or an example how to use namespaces in third party modules?

Astrid Günther

unread,
Dec 21, 2018, 6:21:17 AM12/21/18
to Joomla! General Development

In other words. Speaks something against loading the namespace with

$loader = include JPATH_LIBRARIES . '/vendor/autoload.php';
$loader->setPsr4('Joomla\\Module\\Foo\\Site\\', [JPATH_ROOT . "/modules/mod_foo/"]);

Allon Moritz

unread,
Dec 21, 2018, 8:40:18 AM12/21/18
to joomla-de...@googlegroups.com
You can define the namespace in the manifest and it should then update the internal joomla core classmap.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send email to joomla-de...@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

Astrid Günther

unread,
Dec 21, 2018, 5:00:15 PM12/21/18
to Joomla! General Development
Thank you very much Allon. I did not look at the XML file well enough. After your tip, it was clear.


So that not others have the same problem as me, I started to rewrite the module tutorial for Joomla 4.

So far it can only be seen on my user page: https://docs.joomla.org/User:Astridx

How do you see this? Is it too early to start such a tutorial? Did I write something wrong or should I / can I submit it to JDoc for publishing?

Allon Moritz

unread,
Dec 22, 2018, 10:20:03 AM12/22/18
to joomla-de...@googlegroups.com
On the module side, I do not expect big changes till the final release. But I would coordinate with George which is the release lead if it is inline with his idea.

--
Reply all
Reply to author
Forward
0 new messages