MortgageCalculatorController.php in Real Estate Mortgage Calculator 8
File
src/Controller/MortgageCalculatorController.php
View source
<?php
namespace Drupal\mortgage_calculator\Controller;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\State\StateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Controller\ControllerBase;
class MortgageCalculatorController extends ControllerBase {
protected $state;
public function __construct(StateInterface $state) {
$this->state = $state;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('state'));
}
public function mortgageCalculatorPage(Request $request, RouteMatchInterface $route_match) {
$form = $this
->formBuilder()
->getForm('Drupal\\mortgage_calculator\\Form\\MortgageCalculatorForm');
$session = $request
->getSession();
$loan_amount = $session
->get('mortgage_calculator_loan_amount', '');
$mortgage_rate = $session
->get('mortgage_calculator_mortgage_rate', '');
$years_to_pay = $session
->get('mortgage_calculator_years_to_pay', '');
$desired_display = $this->state
->get('mortgage_calculator_desired_display');
return [
'#theme' => 'mortgage_calculator',
'#mortgage_calculator_form' => $form,
'#loan_amount' => $loan_amount ? $loan_amount : '30000',
'#mortgage_rate' => $mortgage_rate ? $mortgage_rate : '3',
'#years_to_pay' => $years_to_pay ? $years_to_pay : 30,
'#desired_display' => $desired_display,
];
}
}