Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
other
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
29 Jun 2009 at 20:18 UTC
Updated:
14 Mar 2013 at 02:26 UTC
Core and contrib use two ways to define associative arrays:
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'));
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
);
The second way is much more readable. I suggest we add a rule to the coding standards arrays should be defined like that.
Comments
Comment #1
cweagans+1
I agree 100%
Comment #2
berdirThat's what we do with DBTNG too..
Two exceptions:
arrays that just have values, example:
Arrays that contain only a single value:
I think it doesn't make sense to split these to multiple lines.
Comment #3
xanoIf we put arrays with one key-value pair on a single line we need an exception to the rule again. I say we use the multiline approach as soon as we specify keys as well. Use cases are markup elements in forms. They generally (only?) have one property, but if that property's on a new line, the element is easily recognisable.
Comment #4
jayavelraj commentedWe are talking about associative arrays. There is no question of "arrays that just have values" if it is an associative array.
I think its good to stick on with the second one since it is more readable.
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
);
As far as "Arrays that contain only a single value" I agree with you for having an exception.
Comment #5
cburschkaThis is not a patch. Also, it seems the mailing list might be a better place to discuss standards... but that's a matter of opinion.
Comment #6
xanoThe status doesn't necessarily have to do with patches. The proposal still needs review.
Comment #7
axyjo commentedTagging + subscribing.
Comment #8
sunAdding a general purpose rule for this makes no sense.
We may consider a "recommendation" for form structures and renderable arrays to write them on multiple lines.
But then again, there's no good reason to wrap something that fits into 80 chars. This is the general purpose rule of thumb we really follow.
Comment #9
montesq commentedI think that http://drupal.org/coding-standards#array sums up clearly the situation. As a consequence, I suggest to close this issue
Comment #10
xanoWe have this in \Drupal\Core\Entity\EntityNG now, which is just insane:
Comment #11
cweagansThat's not something we need to reopen this issue for. Go file a patch to fix it in \Drupal\Core\Entity\EntityNG. It's 98 characters long, and in clear violation of the agreed upon coding standards.