public function DemoWidgetFormsController::widgets in Geolocation Field 8
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 'DemoWidgetFormsController::widgets'
- 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/ DemoWidgetFormsController.php, line 61
Class
- DemoWidgetFormsController
- Returns responses for geolocation_demo module routes.
Namespace
Drupal\geolocation_demo\ControllerCode
public function widgets(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');
$field_definition = $node
->getFieldDefinition('field_geolocation_demo_single');
$widget_settings = [
'field_definition' => $field_definition,
'form_mode' => 'default',
// No need to prepare, defaults have been merged in setComponent().
'prepare' => TRUE,
'configuration' => [
'settings' => [],
'third_party_settings' => [],
],
];
$form_state = new FormState();
$form = [];
foreach ([
'geolocation_googlegeocoder',
'geolocation_latlng',
'geolocation_html5',
] as $widget_id) {
$widget = $this->pluginManagerFieldWidget
->getInstance(array_merge_recursive($widget_settings, [
'configuration' => [
'type' => $widget_id,
],
]));
$form[$widget_id] = $widget
->formElement($items, 0, [
'#title' => $widget
->getPluginDefinition()['label'],
], $form, $form_state);
}
return $form;
}