You are here

public function DemoWidget::getWidgetForm in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 modules/geolocation_demo/src/Form/DemoWidget.php \Drupal\geolocation_demo\Form\DemoWidget::getWidgetForm()
3 calls to DemoWidget::getWidgetForm()
GooglegeocoderWidget::buildForm in modules/geolocation_google_maps/modules/geolocation_google_maps_demo/src/Form/GooglegeocoderWidget.php
Form constructor.
Html5Widget::buildForm in modules/geolocation_demo/src/Form/Html5Widget.php
Form constructor.
LatlngWidget::buildForm in modules/geolocation_demo/src/Form/LatlngWidget.php
Form constructor.

File

modules/geolocation_demo/src/Form/DemoWidget.php, line 51

Class

DemoWidget
Returns responses for geolocation_demo module routes.

Namespace

Drupal\geolocation_demo\Form

Code

public function getWidgetForm($widget_id, array $form, FormStateInterface $form_state) {

  /** @var \Drupal\node\NodeInterface $node */
  $node = $this->entityTypeManager
    ->getStorage('node')
    ->create([
    'type' => 'geolocation_default_article',
  ]);
  $field_name = 'field_geolocation_demo_multiple';
  $field_definition = $node
    ->getFieldDefinition($field_name);
  $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' => [],
    ],
  ];
  $widget = $this->pluginManagerFieldWidget
    ->getInstance(array_merge_recursive($widget_settings, [
    'configuration' => [
      'type' => $widget_id,
    ],
  ]));
  $items = $node
    ->get($field_name);
  $form['#parents'] = [];
  return $widget
    ->form($items, $form, $form_state);
}