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/FixMyStreet/App/Controller/Report/New.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/FixMyStreet/App/Controller/Report/New.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index b5a6745b2..b4daf0f55 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -636,8 +636,9 @@ sub setup_categories_and_bodies : Private { unless ( $seen{$contact->category} ) { push @category_options, $contact->category; - $category_extras{ $contact->category } = $contact->extra - if $contact->extra; + my $metas = $contact->get_extra_fields; + $category_extras{ $contact->category } = $metas + if scalar @$metas; $non_public_categories{ $contact->category } = 1 if $contact->non_public; } @@ -870,8 +871,9 @@ sub process_report : Private { if $body_string && @{ $c->stash->{missing_details_bodies} }; $report->bodies_str($body_string); - my @extra = (); - my $metas = $contacts[0]->extra; + my @extra; + # NB: we are only checking extras for the *first* retrieved contact. + my $metas = $contacts[0]->get_extra_fields(); foreach my $field ( @$metas ) { if ( lc( $field->{required} ) eq 'true' ) { @@ -894,7 +896,7 @@ sub process_report : Private { if ( @extra ) { $c->stash->{report_meta} = { map { $_->{name} => $_ } @extra }; - $report->extra( \@extra ); + $report->set_extra_fields( @extra ); } } elsif ( @{ $c->stash->{bodies_to_list} } ) { |