public function DemoFormattersController::formatters in Geolocation Field 8
Same name and namespace in other branches
- 8.3 modules/geolocation_demo/src/Controller/DemoFormattersController.php \Drupal\geolocation_demo\Controller\DemoFormattersController::formatters()
- 8.2 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' => 'The date is [current-date:html_date] and the latitude value [geolocation_current_item:lat]',
],
'third_party_settings' => [],
],
'view_mode' => 'default',
];
$form = [];
foreach ([
'geolocation_latlng',
'geolocation_map',
'geolocation_sexagesimal',
'geolocation_token',
] 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;
}