Jump to content

Ideas on naming fields in custom modules


clsource
 Share

Recommended Posts

Hello,

I was thinking that some modules use custom fields.

The problem is that they could conflict with already existing fields on the site.

example:

you module wants to use a field named "category", but the site already stores a "category" field

that has a different implementation, other field type, etc.

The solution I think is simple, just add a prefix to the fields that the module uses.

three letters and a underscore before the field name.

example

cls_category

But its prettier to call

"$module->category" than  "$module->cls_category"

This will be solved using a simple module just for hooks

that is installed alongside our module.

$wire->addHookProperty("Page(template=cls_mymodule)::category", function(HookEvent $event){
    $page = $event->object;
    return $event->return = $page->cls_category;
});

We are adding a property hook that simplifies the field name. This way it can be called like $module->category

also the template names are prefixed.

Please tell me if there are other ways :)

thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...