<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package FixMyStreet::App::Form::Waste;

use HTML::FormHandler::Moose;
extends 'FixMyStreet::App::Form::Wizard';

has default_page_type =&gt; ( is =&gt; 'ro', isa =&gt; 'Str', default =&gt; 'Waste' );

has finished_action =&gt; ( is =&gt; 'ro' );

before _process_page_array =&gt; sub {
    my ($self, $pages) = @_;
    foreach my $page (@$pages) {
        $page-&gt;{type} = $self-&gt;default_page_type
            unless $page-&gt;{type};
    }
};

# Add some functions to the form to pass through to the current page
has '+current_page' =&gt; (
    handles =&gt; {
        intro_template =&gt; 'intro',
        title =&gt; 'title',
        template =&gt; 'template',
    }
);

sub wizard_finished {
    my ($form, $action) = @_;
    my $c = $form-&gt;c;
    my $success = $c-&gt;forward($action, [ $form ]);
    if (!$success) {
        $form-&gt;add_form_error('Something went wrong, please try again');
        foreach (keys %{$c-&gt;stash-&gt;{field_errors}}) {
            $form-&gt;add_form_error("$_: " . $c-&gt;stash-&gt;{field_errors}{$_});
        }
    }
    return $success;
}

# Make sure we can have pre-ticked things on the first page
before after_build =&gt; sub {
    my $self = shift;

    my $saved_data = $self-&gt;previous_form ? $self-&gt;previous_form-&gt;saved_data : $self-&gt;saved_data;

    my $c = $self-&gt;c;

    my %fields = map { $_-&gt;name =&gt; 1 } @{$self-&gt;fields};
    map { $saved_data-&gt;{$_} = 1 } grep { /^(service|container)-/ &amp;&amp; $fields{$_} &amp;&amp; $c-&gt;req-&gt;params-&gt;{$_} } keys %{$c-&gt;req-&gt;params};
    if (my $choice = $c-&gt;get_param('container-choice')) {
        $saved_data-&gt;{'container-choice'} = $choice if $fields{'container-choice'};
    }
};

sub validate {
    my $self = shift;

    my $email = $self-&gt;field('email');
    my $phone = $self-&gt;field('phone');
    return 1 unless $email &amp;&amp; $phone;

    my $c = $self-&gt;c;
    my $cobrand = $c-&gt;cobrand-&gt;moniker;
    my $is_staff_user = ($c-&gt;user_exists &amp;&amp; ($c-&gt;user-&gt;from_body || $c-&gt;user-&gt;is_superuser));
    my $staff_provide_email = (ref $self) =~ /Garden/ &amp;&amp; $c-&gt;cobrand-&gt;call_hook('garden_staff_provide_email');

    $email-&gt;add_error('Please provide an email address')
        unless $email-&gt;is_inactive || $email-&gt;value || ($is_staff_user &amp;&amp; !$staff_provide_email);

    $email-&gt;add_error('Please provide email and/or phone')
        unless $phone-&gt;is_inactive || $phone-&gt;value || $email-&gt;value || !($is_staff_user &amp;&amp; !$staff_provide_email) || $cobrand eq 'bromley';
}

1;
</pre></body></html>