Hello,

Most developers I've worked with create helper functions in custom modules.
There are common things that most installations would use, and having them in a separate module would reduce the amount of code necessary for regular things.

Here are some examples:

  • Generating a random string of arbitrary length
  • Check if a user has a specific role
  • Check if a request is an AJAX request. Useful when overriding tricky form elements, e.g. setting a default value on Addressfield on checkout page with Commerce.
  • Secure string comparison from HTTP Auth library of Zend Framework
  • Get the name of the country given the abbreviation
  • Get the public path for default user avatars
  • Get user profile image or a default one, using a specific image style
  • Things for administrative forms:
    • Get the list of all image styles on the site
    • Get the list of all nodes on the site
    • Get the list of all node types on the site
    • Get the list of all users on the site
    • Get the list of all roles on the site
    • Get the list of all vocabularies on the site
    • Get the list of all vocabulary terms on the site

I'm sure there are more functions that could be added here.

If this is accepted by others, I am willing to do this myself, and provide patches here for review.
This could be either added to the ctools.module file or in a separate submodule.

Let me know what you think.

Thanks!

Comments

yanniboi’s picture

Why would these helper functions go into ctools module rather than a 'Dev Helper' module? Personally if they were added to ctools, I would never use them because I wouldn't know they were there.

But the concept of a dev helper functions module does sound great! :)

aramboyajyan’s picture

Thanks for fast response; these can be added to a submodule instead of the main ctools module, for example ctools_dev.

Not knowing about them is a good point. This can be one of the main arguments for separating this in a dedicated module. It will be more prominent, so more people will pay attention to it and look up what's available.

aramboyajyan’s picture

Assigned: Unassigned » aramboyajyan

Forgot to assign the issue to myself.

Question for the maintainers: could you confirm if you are interested in such functionality at all?

If yes, I can create a repo (Github/sandbox) where I would add these things, so you can see the code upfront.
If no, I will probably release this as a separate module for developers.

Thanks.