Questions tagged [coding-standards]

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

Filter by
Sorted by
Tagged with
3 votes
0 answers
43 views

Array type hints conflict between Drupal and Symfony

In an event subscriber, I have: /** * Registers the methods in this class that should be listeners. * * @return array * An array of event listener definitions. */ public static ...
1 vote
0 answers
39 views

Interfaces for entities? [closed]

The Drupal code standards explains that I should use interfaces. And I always did that. But I never understood why. because it allows more flexibility in extending code later Why does an interface ...
0 votes
1 answer
33 views

How to point phpcbf to the folder standards? [duplicate]

After installing PHP_CodeSniffer on Kali with composer, I added point phpcs to the folder with standards (Drupal & DrupalPractice) where they are located, to run CodeSniffer globally by alias ...
  • 7
-2 votes
1 answer
102 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 ...
  • 366
4 votes
2 answers
60 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
1 answer
58 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 ...
  • 2,115
2 votes
0 answers
190 views

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

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
1 answer
91 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
2 answers
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
2 answers
69 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
2 answers
189 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
3 answers
1k 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
1 answer
357 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 ...
  • 145
2 votes
1 answer
553 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 ...
  • 653
0 votes
1 answer
56 views

Why are non-standard file extension used for PHP files?

Is there any reason why Drupal decided to use non-standard file extensions, for example node.install, node.module, simple.profile, case.test? Why doesn't Drupal use .php as extension for PHP files?
1 vote
1 answer
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
1 answer
487 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. //<--- ...
  • 331
4 votes
1 answer
106 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'); ...
  • 4,604
1 vote
2 answers
60 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
1 answer
456 views

Naming conventions for permissions

Looking through the Drupal coding conventions on Coding standards / Naming Conventions, I have seen module, variable, function, and many other areas but not for permission names. Is there any ...
  • 81
4 votes
2 answers
573 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
1 answer
315 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 ...
  • 27.5k
3 votes
2 answers
3k views

What's the coding standard for class constants?

For general constants, Coding standards / Naming Conventions says that constants should always be all-uppercase, with underscores to separate words and that module-defined constant names should also ...
5 votes
3 answers
608 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 ...