You are here

function openlayers_map_form_interactions in Openlayers 7.3

Map interactions config form handler.

1 string reference to 'openlayers_map_form_interactions'
openlayers_ui_OpenlayersMaps_ctools_export_ui in modules/openlayers_ui/src/Plugin/export_ui/OpenlayersMaps.inc
CTools Export UI plugin definition.

File

modules/openlayers_ui/src/Plugin/export_ui/OpenlayersMaps.inc, line 529
CTools Export UI plugin definition for maps.

Code

function openlayers_map_form_interactions($form, &$form_state) {
  $map = \Drupal\openlayers\Openlayers::load('map', $form_state['item']);
  $all_interactions = \Drupal\openlayers\Openlayers::loadAll('Interaction');
  $header = array(
    'name' => t('Name'),
    'machine_name' => t('Machine name'),
    'description' => t('Description'),
    'operations' => t('Operations'),
  );
  array_walk($all_interactions, function (\Drupal\openlayers\Types\InteractionInterface $interaction) {
    $interaction
      ->setWeight(0);
    $interaction->enabled = 0;
  });
  foreach ($map
    ->getObjects('interaction') as $interaction) {

    /** @var Drupal\openlayers\Types\InteractionInterface $interaction */
    $all_interactions[$interaction
      ->getMachineName()]
      ->setWeight($interaction
      ->getWeight());
    $all_interactions[$interaction
      ->getMachineName()]->enabled = 1;
  }
  uasort($all_interactions, function (\Drupal\openlayers\Types\InteractionInterface $a, \Drupal\openlayers\Types\InteractionInterface $b) {
    if ($a->enabled > $b->enabled) {
      return -1;
    }
    elseif ($a->enabled < $b->enabled) {
      return 1;
    }
    if ($a
      ->getWeight() < $b
      ->getWeight()) {
      return -1;
    }
    elseif ($a
      ->getWeight() > $b
      ->getWeight()) {
      return 1;
    }
    if ($a
      ->getMachineName() < $b
      ->getMachineName()) {
      return -1;
    }
    elseif ($a
      ->getMachineName() > $b
      ->getMachineName()) {
      return 1;
    }
    return 0;
  });
  $rows = array();
  foreach ($all_interactions as $interaction) {
    $rows[$interaction
      ->getMachineName()] = array(
      'name' => $interaction
        ->getName(),
      'machine_name' => $interaction
        ->getMachineName(),
      'description' => $interaction
        ->getDescription(),
      'operations' => l(t('Edit'), 'admin/structure/openlayers/interactions/list/' . $interaction
        ->getMachineName() . '/edit/options', array(
        'query' => array(
          'destination' => current_path(),
        ),
      )),
    );
  }
  $form['options']['#tree'] = TRUE;
  if (!isset($form_state['item']->options['interactions'])) {
    $form_state['item']->options['interactions'] = array();
  }
  $form['options']['interactions'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#default_value' => drupal_map_assoc($form_state['item']->options['interactions']),
  );
  return $form;
}