-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperty_list.module
More file actions
78 lines (72 loc) · 1.59 KB
/
property_list.module
File metadata and controls
78 lines (72 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* @file
* Module for listing properties received from API
*/
use Drupal\property_list\Form\FromToForm;
/**
* Implements hook_theme().
*/
function property_list_theme()
{
return [
'properties_page' => [
'variables' => [
'properties' => []
]
],
'property_list' => [
'variables' => [
'properties' => [],
'pager' => null,
'empty' => null
]
],
'property_item' => [
'variables' => [
'property' => null
]
]
];
}
/**
* Default template: properties-page.html.twig.
*
* @param $variables
*/
function template_preprocess_properties_page(&$variables)
{
$form = \Drupal::formBuilder()->getForm(FromToForm::class);
$variables['form'] = $form;
$properties = [];
foreach ($variables['properties'] as $property) {
$properties[] = [
'property' => [
'#theme' => 'property_item',
'#property' => $property
]
];
}
$variables['property_list'] = [
'#theme' => 'property_list',
'#properties' => $properties,
'#empty' => t('We could not find any available properties for these dates')
];
}
/**
* Default template: property-list.html.twig.
*
* @param $variables
*/
function template_preprocess_property_list(&$variables)
{
$from = \Drupal::request()->query->get('from', date('Ymd'));
$to = \Drupal::request()->query->get('to', date('Ymd', strtotime('last day of december this year')));
$variables['pager'] = [
'#type' => 'pager',
'#parameters' => [
'from' => $from,
'to' => $to
]
];
}