You are here

public function MortgageCalculatorBlockResults::build in Real Estate Mortgage Calculator 8

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/MortgageCalculatorBlockResults.php, line 60

Class

MortgageCalculatorBlockResults
Provides a 'Example: uppercase this please' block.

Namespace

Drupal\mortgage_calculator\Plugin\Block

Code

public function build() {
  $request = $this->requestStack
    ->getCurrentRequest();
  $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 = $session
    ->get('mortgage_calculator_desired_display', '');
  $output = [
    '#theme' => 'mortgage_calculator',
    '#help' => 'Help topics',
    '#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,
  ];
  return $output;
}