diff options
author | Hakim Cassimally <hakim@mysociety.org> | 2015-02-13 17:12:21 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-03-20 20:30:40 +0000 |
commit | 6d9c719d25e2450ee2f31a5f305b603c2f451594 (patch) | |
tree | afc3b450191ce752cbe3ee67450875dba73e052e /perllib/Open311.pm | |
parent | 10b3a899af00205e46e177509a0b4c13bf746299 (diff) |
Add Extra role to ease use of {extra} field.
Historically, the extra field has been used in two different ways by
different cobrands, both as a list (e.g. Open311 category fields) and a
hash (e.g. the Zurich cobrand).
This commit consolidates usage, adding an API to make use of the field
easier and always returning a hash for the code to use. Fixes #1018.
Diffstat (limited to 'perllib/Open311.pm')
-rw-r--r-- | perllib/Open311.pm | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/perllib/Open311.pm b/perllib/Open311.pm index c02618725..58ae96bc2 100644 --- a/perllib/Open311.pm +++ b/perllib/Open311.pm @@ -150,19 +150,15 @@ sub _populate_service_request_params { $params->{deviceid} = $problem->service; } - if ( $problem->extra ) { - my $extras = $problem->extra; - - for my $attr ( @$extras ) { - my $attr_name = $attr->{name}; - if ( $attr_name eq 'first_name' || $attr_name eq 'last_name' ) { - $params->{$attr_name} = $attr->{value} if $attr->{value}; - next if $attr_name eq 'first_name'; - } - $attr_name =~ s/fms_extra_//; - my $name = sprintf( 'attribute[%s]', $attr_name ); - $params->{ $name } = $attr->{value}; + for my $attr ( @{$problem->get_extra_fields} ) { + my $attr_name = $attr->{name}; + if ( $attr_name eq 'first_name' || $attr_name eq 'last_name' ) { + $params->{$attr_name} = $attr->{value} if $attr->{value}; + next if $attr_name eq 'first_name'; } + $attr_name =~ s/fms_extra_//; + my $name = sprintf( 'attribute[%s]', $attr_name ); + $params->{ $name } = $attr->{value}; } return $params; |