-
Notifications
You must be signed in to change notification settings - Fork 1
/
CityPageController.php
69 lines (60 loc) · 1.64 KB
/
CityPageController.php
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
<?php
namespace Drupal\cheap_advisor\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\cheap_advisor\Plugin\CityWidgetManager;
/**
* Class CityPageController.
*/
class CityPageController extends ControllerBase {
/**
* Drupal\cheap_advisor\Plugin\CityWidgetManager definition.
*
* @var \Drupal\cheap_advisor\Plugin\CityWidgetManager
*/
protected $pluginManagerCityWidget;
/**
* Constructs a new CityPageController object.
*/
public function __construct(CityWidgetManager $plugin_manager_city_widget) {
$this->pluginManagerCityWidget = $plugin_manager_city_widget;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.city_widget')
);
}
/**
* Return page title.
*
* @param string $city
* The city, as passed by the request.
*
* @return string
* The page title.
*/
public function pageTitle($city) {
return $city;
}
/**
* Build the City page content.
*
* @param string $city
* The city, as passed by the request.
*
* @return array
* Return city page content render-able array.
*/
public function pageContent($city) {
$output = [];
foreach (array_keys($this->pluginManagerCityWidget->getDefinitions()) as $plugin_id) {
/** @var \Drupal\cheap_advisor\Plugin\CityWidgetInterface $widget */
$widget = $this->pluginManagerCityWidget->createInstance($plugin_id);
$output[$widget->getPluginId()] = $widget->buildWidget($city);
}
return $output;
}
}