2

I have a component which creates content pages for custom entities.

I have an xml which allows to set those pages as menu items of that entity type.

I have 1 module that I always want to display on menu items of that type.

I have 1 module that I never want to display on menu items of that type.

Now I am trying to figure out how to spare my customer the hassle to keep going to the module manager to set and unset the module assignments every time they create a new menu item.

Is there a way to programmatically set the module assignments at time of menu creation? I have figured out where and how the assigments are stored in the database, but cannot seem to find an event for a plugin to hook into at menu creation.

Any hints or clues how to approach this?

2 Answers 2

1

Maybe it would be a good idea to merge the 2 modules into a single dynamic one. Then in this module you can check with JInput for the current content type/view and conditionally display the desired data from inside the module.

If the content type is of that menu item, then display data for the first module, otherwise display data for the second module.

1
  • That probably would work, indeed. But the problem is that one of the modules is a 3rd party that I'd like to leave untouched. Also the more generic the solution can be the better. It's mostly a userbility problem of the Joomla module assignment. Jul 26, 2016 at 12:56
1

Extending on FFrewin's idea, could you create dynamic module positions in your template that only appear when the appropriate conditions are met, and assign the modules accordingly? ie do it at template level rather than module level so that the third party modules can remain untouched.

Another suggestion would be to create a third bespoke module that loads the other modules programatically, as opposed to assigning them via the module manager.

Alternatively, the quick-and-nasty approach would be to just add a CSS file to your component's view that shows/hides the modules with CSS. I don't believe hidden content is really a major SEO issue any more, it just makes the page a bit heavier.

1
  • Interesting thoughts. The quick and nasty approach might work if it wasn't for the modules loading the screen-wide banner images, so the extra heavy would be rather bad. The other two depends on how easily I can distinguish the menu-types. The module loading module sounds more clean there, I might try that when I get back to the project. A real way to hook into and manage module assignment would still be interesting though. Mar 24, 2017 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.