You are here

public function Field::optionsForm in Openlayers 7.3

@TODO What is this return? If it is the form, why is form by reference?

Overrides Base::optionsForm

File

modules/openlayers_field/src/Plugin/Source/Field/Field.php, line 31
Source: Field.

Class

Field
Class Field.

Namespace

Drupal\openlayers_field\Plugin\Source\Field

Code

public function optionsForm(array &$form, array &$form_state) {
  $geocoder_handlers = array();
  foreach (geocoder_handler_info() as $name => $handler) {
    $geocoder_handlers[$name] = $handler['title'];
  }
  $form['options']['geocoder_handler'] = array(
    '#type' => 'select',
    '#title' => t('Geocoder handler'),
    '#options' => $geocoder_handlers,
    '#required' => TRUE,
    '#default_value' => $this
      ->getOption('geocoder_handler', 'google'),
  );
  drupal_add_tabledrag('entry-order-geocoder-handlers', 'order', 'sibling', 'entry-order-weight');
  $form['options']['geocoder_cache'] = array(
    '#type' => 'select',
    '#title' => t('Geocoder cache type'),
    '#description' => t('Type of geocoder cache to use'),
    '#options' => array(
      0 => t('No caching'),
      1 => t('Static-cache but no persistent-cache'),
      2 => t('Both static-cache and persistent-cache'),
    ),
    '#default_value' => $this
      ->getOption('geocoder_cache', 0),
  );
  $fields = $this
    ->getOption('fields', array(
    array(),
  ));
  if (!empty($fields[0])) {
    $fields[] = array();
  }
  foreach ($fields as $index => $field) {
    $form['options']['fields'][$index] = array(
      '#type' => 'fieldset',
      '#title' => $field == end($fields) ? t('Add a new feature') : 'Feature ' . $index,
      '#collapsible' => TRUE,
      '#collapsed' => $field == end($fields) ? TRUE : FALSE,
      'title' => array(
        '#title' => 'Title',
        '#type' => 'textfield',
        '#default_value' => isset($fields[$index]['title']) ? $fields[$index]['title'] : '',
      ),
      'description' => array(
        '#title' => 'Description',
        '#type' => 'textarea',
        '#default_value' => isset($fields[$index]['description']) ? $fields[$index]['description'] : '',
      ),
      'address' => array(
        '#title' => 'Address',
        '#type' => 'textfield',
        '#default_value' => isset($fields[$index]['address']) ? $fields[$index]['address'] : '',
      ),
      'geojson' => array(
        '#type' => 'textarea',
        '#title' => 'GeoJson',
        '#disabled' => TRUE,
        '#default_value' => isset($fields[$index]['geojson']) ? $fields[$index]['geojson'] : '',
      ),
    );
  }
}