Questions tagged [coding-standards]

Use it for questions about Drupal coding standards and the tools to follow them.

Filter by
Sorted by
Tagged with
-2
votes
1answer
63 views

PSR12, Drupal or DrupalPractice? [closed]

I want to respect coding standard in my new Drupal projects (for Drupal 8 and Drupal 9). Using phpcs and phpcbf, I am wondering if I should use PSR12, Drupal, or DrupalPractice coding standards. Do ...
3
votes
2answers
807 views

Alternative for .inc files

I was wondering what is the correct alternative of .inc files in Drupal 8? That is to say, if I want to create some functions that should be only be loaded when required, like it was with ...
4
votes
2answers
55 views

Does a third-party module need to implement hook_help()?

After having spent hours reading through (very old) coding standards and best practices threads on drupal.org, and even trying to revive the Contrib Development Best Practices group on groups.drupal....
0
votes
1answer
51 views

Dependecies prefix coding standard

Running phpcs --standard=DrupalPractice in several modules *.info.yml file I get a warning message: All dependencies must be prefixed with the project name I've seen some modules that use the ...
1
vote
0answers
156 views

Where to place the utility and internal functions for a custom module?

I have a custom module with some utility (can be used for other modules) and internal (can be used only for the module) functions inside, so I decide to place this functions in another file. But ...
4
votes
1answer
87 views

When to use a php function vs a drupal_ equivalent function?

I come from update my Coder module to the v1.3 and when I go to check one custom module I see the following message: Line 71: in most cases, replace the string function with the drupal_ ...
5
votes
2answers
3k views

Are there any naming conventions for helper functions in modules?

I'm writing a module and I need to create an auxiliary (helper) function, but I don't know which is the best name to my function. Should I name my function like: function _MODULE_my_function or: ...
-1
votes
2answers
65 views

Is my code valid and how does it relate to the coding standards?

How does the below piece of code relate to the Drupal (7) coding standards? Notice that the function is not returning anything. $a = foo(); function foo() { // Doing everything except returning. ...
3
votes
2answers
178 views

PHP switch and translations

Given a PHP switch statement, would it be a good (or bad) idea to use t() in case statements? switch ($button_value) { case t('Clear'): // … break; case t('Search'): // … break; }
10
votes
3answers
912 views

How to fix "Hook implementations should not duplicate @param documentation."?

I am using PhpStorm to experiment with cleaning up my code in a custom module. For the following function, I'm getting this warning: Hook implementations should not duplicate @param documentation. ...
4
votes
1answer
326 views

Where to write public, common, utility functions in Drupal?

At times you have to write little utility functions which will have a general scope (not restricted to the module you are working on) so that it can be called from anywhere in the project. I know I ...
2
votes
1answer
506 views

Coding standards for long strings?

I've been looking for some official guidelines on how to format long strings in module code, but the closest thing I've found is an ambiguous section on indenting long SQL queries which suggests any ...
0
votes
1answer
48 views

Why does Drupal use strange file extension for PHP code?

Is there any hidden reason why Drupal developer decided to use strange file extensions — for example node.install, node.module, simple.profile, case.test? Why not just using stand .php extension? ...
0
votes
3answers
209 views

Drupal Coding Standards (request_uri)

I'm trying to write a patch to make module Drupal coding standards. And this one the complains that have and I do not know how to fix it. Line 148: the use of REQUEST_URI is prone to XSS exploits ...
1
vote
1answer
2k views

/README.txt: UTF-8 Unicode (with BOM) English text, with CRLF line terminators

I have been working on a Drupal.org project and I want to make sure that pass all the coding standards. For some reason I got these problem with the README.txt encoding and I dont know how to solve it....
0
votes
1answer
442 views

Parameter comment must be on the next line at position 1

I review my module code with http://pareview.sh and it returns an error: Line #94 - ERROR | Parameter comment must be on the next line at position 1 /** * Fetch node object properties. //<--- ...
4
votes
1answer
103 views

Breaking on to new lines?

If I have a long line of code that exceeds 80 characters, like this: $last_response = '<strong>' . t('Last response: ') . '</strong>' . format_interval((time() - $last), 1) . t(' ago'); ...
1
vote
2answers
57 views

PAReview.sh error, Expected "switch (...) {\n"; found "switch(...) {\n"

In my theme's template.php file, I have a custom function as: function _MYTHEME_content_grid($columns = 1) { $class = FALSE; switch($columns) { // No sidebars, just content. case 1:{ ...
4
votes
1answer
428 views

Naming conventions for Drupal permissions

Looking through the Drupal coding conventions http://drupal.org/coding-standards#naming I have seen module, variable, function, and many other areas but not for permission names. Are there any ...
4
votes
2answers
569 views

Can custom module function names contain characters between 7F and FF?

PHP defines valid function names as [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*. I have already been bitten by Drupal name conflicts when using hook_form_alter clashing with my module name when it ...
2
votes
1answer
314 views

Would PHPLint's advice be beneficial to our community?

I recently found this static PHP code analyzer called PHPLint. One of the things it can do, is look at code like this: /** * @return string */ function getText() { return 5; } And complain that ...
3
votes
2answers
2k views

What's the coding standard for class constants?

I'm trying to figure out the proper naming convention for class constants. For general constants, the coding standards states: Constants should always be all-uppercase, with underscores to ...
5
votes
3answers
606 views

Best practice for avoiding module / theme / profile name clashes?

We currently have our code managed such that each site has its own theme and install profile. These have naturally evolved in such a way that the names of these items (and their directories) tend to ...