Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions about Drupal coding standards, and the tools to follow them.

2
votes
1answer
40 views

What's the difference between drupalSettings and settings parameter in behaviors?

When having the need to pass settings or parameters from PHP to JavaScript, i always used to do so according to a blog post from Acquia - create a dependency to drupalSettings, attach the settings on ...
2
votes
2answers
66 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 ...
1
vote
1answer
88 views

How to create a test configuration that can called in a test class?

I am attempting to write a unit test by extending UnitTestCase. Below is how my code works, but I need a way to create a test (or mock) configuration that can be used to satisfy the testing. How can ...
0
votes
0answers
15 views

Constants in templates

In terms of standards, is it okay to use a constant in a template file, or should its value be passed in via the variables? E.g Template: <div><?php print MY_CONSTANT; ?></div> ...
1
vote
1answer
30 views

Drupal contrib modules best practices regarding 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....
-1
votes
1answer
19 views

Call to Undefined Function That Exists

I have a function in my module called mymodule_date_parser and looks something like this. function mymodule_date_parser($date){ //do some things with a birthdate specific to the module } I call ...
0
votes
1answer
34 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
68 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 ...
1
vote
1answer
214 views

How to do join on Drupal dynamic query

Following the documentation on https://www.drupal.org/docs/7/api/database-api/dynamic-queries/joins I have constructed a very simple dynamic query with join: $query = db_select('node', 'n') ->...
0
votes
2answers
56 views

How to return empty variables in Drupal functions [closed]

This might be a generic PHP question, but I am trying to understand what is the best way in my case to stay in compliance with Drupal standards. So I have a simple function: function custom($uid) { ...
4
votes
1answer
55 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_ ...
4
votes
2answers
644 views

How to name an auxiliary (helper) function in a Drupal module?

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: ...
8
votes
4answers
1k views

How to decide between module_exists and function_exists?

I'm familiar with using module_exists in a module, and using it in situations like: Enable some extra functionality in a module, provided some other module is available in the site also. The ...
-2
votes
2answers
62 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
72 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; }
1
vote
1answer
35 views

Including a large amount of raw data with a module

I have a module that demonstrates how to use another module (a graphing library). One of my controllers uses a large dataset to generate one of the example graphs. I currently have this data assigned ...
0
votes
1answer
48 views

Drupal PHP Coding Standards

I have declared two items in my hook menu. //Calls a function that enables inputting/updating data of a particular template. $items['user/%user/myid_inputting'] = array( 'title' => 'MyID ...
6
votes
3answers
406 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. ...
3
votes
1answer
135 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
201 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
151 views

How to test if a variable is been sanitized?

I have been doing coder review, and the coder module is showing this complain: Line 111: Potential problem: drupal_set_message() only accepts filtered text, be sure to use check_plain(), filter_xss() ...
0
votes
1answer
62 views

I want to call a mymodule.functions.inc file

Hi all drupalers i am new in drupal coding i wrote a new drupal module that works perfecr but my boss wanted to put all my functions of my .module file in a new folder called 'includes' and in a files ...
6
votes
2answers
241 views

Policy Question: Can I Use a Submodule that Does Not Follow Drupal Code Guidelines?

I have a fairly extensive plugin system that I wrote. It uses an MVVM pattern, where the lions' share of the code is in a cross-CMS class. I haven't submitted the Drupal plugin to the Drupal repo, ...
0
votes
1answer
43 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
152 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 ...
0
votes
2answers
259 views

| WARNING | Unused variable - Coding Standards [closed]

I have been working on a Drupal.org project and I want to make sure that pass all the coding standards. The last thing that is complain is an "Unused variable." I'm using the variable its unclear to ...
1
vote
1answer
1k 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
281 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. //<--- ...
1
vote
2answers
265 views

How can you print the field class you entered in a View 's style settings?

So in Views you can add a CSS class (under style settings) to your field. I need to print the same class in a parent div of the calendar module. The fields are rendered to calendar content with the ...
0
votes
2answers
93 views

Is it bad practice to add markup to title or label fields?

The title might not make sense because I'm not sure what the correct wording is. But here is the example that explains what I mean. I am creating a block view to go at the bottom of a node page that ...
4
votes
1answer
79 views

Coding standards: 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'); ...
0
votes
1answer
105 views

Best practice for writing PDO Query?

I have noticed one thing in all core files: all DB related operations are not in try-catch block. So please suggest me whether it's good practice to put SELECT, UPDATE, INSERT query in try catch ...
1
vote
2answers
50 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
73 views

Do I need hook_update_N if there are no database changes?

I wrote a little module that provides a form and does some special processing of the submission. There are no database tables involved. If I change the form or processing, how do I code the update? ...
2
votes
1answer
37 views

What is best coding practices for providing an upgrade path to a new module version?

I'm getting ready to build a new version of a module of mine. The new version can have an upgrade path from the current version to the new version that will be released, but as you know, new major ...
3
votes
1answer
339 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 ...
1
vote
0answers
260 views

How to hide taxonomy menu items on specific pages?

My situation on D7: I have 6 different menus displayed on the left side region of a Omega theme using with Delta + Context. Each menu is a taxonomy vocabulary created using taxonomy_menu and ...
4
votes
2answers
529 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
68 views

Coder module for Drupal 6 [closed]

Actually, I'm using Drupal 6 and I want my code to be the standard that I used to do things well. Is there a module similar to the Coder module for Drupal 6? I don't have find it.
5
votes
2answers
7k views

Global variable, visible only inside the module

I have several modules, that implement very close functionality. And the SQL requests are almost the same, except for the table name. So I wanted to create a global variable, inside each module: $...
1
vote
3answers
1k views

How to use Drupal Code Sniffer in windows?

How do you configure and use Drupal Code Sniffer in Windows?
2
votes
3answers
841 views

Can we create a core PHP file inside the files folder?

As per Drupal's folder structure, custom code is always in sites/modules or in the theme folder. One of my colleagues created a custom PHP file in the files folder. Is this OK or are there any ...
2
votes
1answer
303 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
997 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 ...
4
votes
2answers
10k views

Where do I declare a global variable?

I need to define a global variable. Where should I define it? I will not use the global variable in template files I should not use settings.php I will only use the global variable in all the custom ...
5
votes
3answers
594 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 ...