Why and how to use getLanguageTopics() in a CMP

In many of the Doodles custom manager page (CMP) tutorial, I see this block of code within the custom controller:

public function getLanguageTopics() {
	return array('doodles:default');

Can someone please explain the following:

  • Why do we override getLanguageTopics() and where is this being called?
  • Where does the value ‘doodles:default’ come from?
  • Is this related to my lexicon file?

Thanks everyone. I have a project coming up that will be needing some i18n so I want to ensure that I understand all the tools at my disposal.

getLanguageTopics() is in the controller object your controller class extends (or one of its parents).

It’s overridden because the parent class doesn’t know which language topics you want to load. getLanguageTopics() tells MODX which lexicon files to load.

In the doodles project, you should have this partial directory structure:


Check the format of default.inc.php, it’s the same for all lexicon files.

The core path {core_path}components/doodles is defined in the doodles namespace object. The lexicon files are assumed to be in the lexicon directory under that core path, so doodles:default comes from the form namespace:lexiconTopic, and MODX knows to load the lexicon file core/components/doodles/lexicon/en/default.inc.php (assuming that en is the manager_language System Setting value).

You can have more than one lexicon file for a project, but many people put everything in default.inc.php. You can have more than one language by putting files in other directories at the same level as the en directory (e.g., de, fr, etc.).

BTW, google translate does a fair (but not perfect) job of translating if you just paste the default.inc.php content.

See this blog post for more information on how to handle lexicon strings for System Settings in transport packages (if your CMP has any System Settings). It’s very non-intuitive.

1 Like

Thanks Bob! One last question then…

In The Collections component, within the CollectionContainerCreateManagerController, there is the following line within the getLanguageTopics() method:

return array(‘resource’, ‘collections:default’, ‘collections:selections’);

What is the purpose of loading multiple language topics and how is this used?

The ‘resource’ topic will come from the MODX core files since it has no namespace (used mainly for the labels of the resource input fields like content, description, etc. That topic would normally be loaded automatically in the Manager, but the environment of the controller file is outside MODX, so it needs to be loaded explicitly.

Some people choose to put all their lexicon strings in a default.in.php file, but if there are a lot of them, or if different parts of the extra require different strings, sometimes they end up in multiple files. The author of collections has chosen to put some files in default.inc.php and others in selections.inc.php.

1 Like

Wonderful, thanks so much Bob!