public function DemoFormattersController::formatters in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 modules/geolocation_demo/src/Controller/DemoFormattersController.php \Drupal\geolocation_demo\Controller\DemoFormattersController::formatters()
- 8 modules/geolocation_demo/src/Controller/DemoFormattersController.php \Drupal\geolocation_demo\Controller\DemoFormattersController::formatters()
Return the non-functional geocoding widget form.
Parameters
\Symfony\Component\HttpFoundation\Request $request: Page request object.
\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.
Return value
array A render array.
1 string reference to 'DemoFormattersController::formatters'
- geolocation_demo.routing.yml in modules/
geolocation_demo/ geolocation_demo.routing.yml - modules/geolocation_demo/geolocation_demo.routing.yml
File
- modules/
geolocation_demo/ src/ Controller/ DemoFormattersController.php, line 60
Class
- DemoFormattersController
- Returns responses for geolocation_demo module routes.
Namespace
Drupal\geolocation_demo\ControllerCode
public function formatters(Request $request, RouteMatchInterface $route_match) {
/** @var \Drupal\node\NodeInterface $node */
$node = $this->entityTypeManager
->getStorage('node')
->create([
'type' => 'geolocation_default_article',
]);
$items = $node
->get('field_geolocation_demo_single');
$default_language = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
$field_definition = $node
->getFieldDefinition('field_geolocation_demo_single');
$widget_settings = [
'field_definition' => $field_definition,
'configuration' => [
'settings' => [
'tokenized_text' => [
'value' => 'The latitude value of this item is: [geolocation_current_item:lat]',
'format' => filter_default_format(),
],
],
'third_party_settings' => [],
],
'view_mode' => 'default',
];
$form = [];
$formatters = [
'geolocation_latlng',
'geolocation_sexagesimal',
'geolocation_token',
];
$moduleHandler = \Drupal::moduleHandler();
if ($moduleHandler
->moduleExists('geolocation_google_maps')) {
$formatters[] = 'geolocation_map';
}
foreach ($formatters as $formatter_id) {
$formatter = $this->pluginManagerFieldFormatter
->getInstance(array_merge_recursive($widget_settings, [
'configuration' => [
'type' => $formatter_id,
],
]));
$form[$formatter_id] = [
'#type' => 'fieldset',
'#title' => $formatter
->getPluginDefinition()['label'],
'widget' => $formatter
->viewElements($items, $default_language),
];
}
return $form;
}