diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-10-04 11:46:29 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-10-04 11:58:06 +0100 |
commit | 505aa9bcba1fe2f419e95cfa5122fab83b6f6ae0 (patch) | |
tree | 9a2118ee5dc352d7a037626a101f1697c40d5210 /perllib/FixMyStreet/App/Controller/Report/New.pm | |
parent | ead4a7ebbd33ac3e6e2c6bf3cb0302189eae99d1 (diff) | |
parent | d8fdbf5d353238d9e4c334f06de251987f7e60cf (diff) |
Merge branch 'issues/forcouncils/36-mobile-inspector-improvements'
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report/New.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index f26120829..7766e08a1 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -849,33 +849,11 @@ sub process_report : Private { $report->bodies_missing($missing); } - my @extra; - foreach my $contact (@contacts) { - my $metas = $contact->get_metadata_for_input; - foreach my $field ( @$metas ) { - if ( lc( $field->{required} ) eq 'true' ) { - unless ( $c->get_param($field->{code}) ) { - $c->stash->{field_errors}->{ $field->{code} } = _('This information is required'); - } - } - push @extra, { - name => $field->{code}, - description => $field->{description}, - value => $c->get_param($field->{code}) || '', - }; - } - } + $c->forward('set_report_extras', [ \@contacts ]); if ( $c->stash->{non_public_categories}->{ $report->category } ) { $report->non_public( 1 ); } - - $c->cobrand->process_open311_extras( $c, $contacts[0]->body_id, \@extra ); - - if ( @extra ) { - $c->stash->{report_meta} = { map { $_->{name} => $_ } @extra }; - $report->set_extra_fields( @extra ); - } } elsif ( @{ $c->stash->{bodies_to_list} } ) { # There was an area with categories, but we've not been given one. Bail. @@ -927,6 +905,36 @@ sub contacts_to_bodies : Private { } } +sub set_report_extras : Private { + my ($self, $c, $contacts, $param_prefix) = @_; + + $param_prefix ||= ""; + my @extra; + foreach my $contact (@$contacts) { + my $metas = $contact->get_metadata_for_input; + foreach my $field ( @$metas ) { + if ( lc( $field->{required} ) eq 'true' ) { + unless ( $c->get_param($param_prefix . $field->{code}) ) { + $c->stash->{field_errors}->{ $field->{code} } = _('This information is required'); + } + } + push @extra, { + name => $field->{code}, + description => $field->{description}, + value => $c->get_param($param_prefix . $field->{code}) || '', + }; + } + } + + $c->cobrand->process_open311_extras( $c, @$contacts[0]->body_id, \@extra ) + if ( scalar @$contacts ); + + if ( @extra ) { + $c->stash->{report_meta} = { map { $_->{name} => $_ } @extra }; + $c->stash->{report}->set_extra_fields( @extra ); + } +} + =head2 check_for_errors Examine the user and the report for errors. If found put them on stash and |