fields() : suggestion on returned array structure
Hi,
Below is an extract of the array returned by fields():
Array
(
[main] => Array
(
[name] => Mail account
[attrs] => Array
(
[0] => Array
(
[id] => mail
[label] => Primary address
[required] => 1
[disabled] =>
[description] => Primary mail address
[value] => test@test.fr
[type] => Array
(
[0] => MailAttribute
[1] => StringAttribute
[2] => Attribute
)
)
[1] => Array
(
[id] => gosaMailServer
[label] => Server
[required] =>
[disabled] =>
[description] => Specify the mail server where the user will be hosted on
[value] =>
(...)
So to access the value of 'mail' attribute, you have to write $fields[main][attrs][0][value], which is not that good for two reasons:
- code readability : there is no mention of "mail" or in the array key(s).
- reliability : Most important consequence of 1), by using an index '0' there is no garantee that the fetched data will be what you expect to...
A straighforward solution for this would be to put the attribute id (name?) in the array key, so you can access the properties with $fields[main][attrs][][value], like $fields[main][attrs][mail][value] or $fields[main][attrs][mail][description]
(from redmine: issue id 4798, created on 2016-05-20, closed on 2016-05-30)
- Custom Fields:
- Bug in version: 1.0.12