Using your own "namespace" for your module to avoid name clashes

  • If you create a new extension (or theme) you usually have a configuration like this:

    JavaScript: composer.json
    1. {
    2. "name": "tobbe/example-plugin",
    3. // [...]
    4. }

    PHP: index.php
    1. <?php
    2. return [
    3. 'name' => 'example-plugin',
    4.     // [...]
    5. ];
    6. ?>

    The name of the module is the name in composer but without the vendor name. This can bring some issues if there is someone who uses the same name for the module in the index.php. The composer file is still fine, but as the settings for example are stored based on the name of the module in the index.php, a name clash can occur. So the best would be to have your own namespace for the module as well. There is just one problem: pagekit expects a module name which is the same as the name in composer, but without the vendor. But you can circumvent this if you tell pagekit which module name to use:

    JavaScript: composer.json
    1. {
    2. "name": "tobbe/example-plugin",
    3. "module": "tobbe/example-plugin",
    4. // [...]
    5. }
    PHP: index.php
    1. <?php
    2. return [
    3. 'name' => 'tobbe/example-plugin',
    4. // [...]
    5. ];
    6. ?>

    A quite small change gives you your own namespace and as long as no one else is using the same vendor name as you, you don't need to worry about name clashes.


    Attention: As the settings are bound to the module name, they are lost if you simply change the name. So for extensions which are already released you mus be careful and you must try to provide a migration script (I never tested whether this is possible).