You are here

public function OpenlayersStyles::list_build_row in Openlayers 7.3

Build a row based on the item.

By default all of the rows are placed into a table by the render method, so this is building up a row suitable for theme('table'). This doesn't have to be true if you override both.

File

modules/openlayers_ui/src/Plugin/export_ui/OpenlayersStyles.php, line 53
Class openlayers_components_ui.

Class

OpenlayersStyles
Class openlayers_components_ui.

Namespace

Drupal\openlayers_ui\UI

Code

public function list_build_row($item, &$form_state, $operations) {

  // Set up sorting.
  $name = $item->{$this->plugin['export']['key']};
  $schema = ctools_export_get_schema($this->plugin['schema']);
  list($plugin_manager, $plugin_id) = explode(':', $item->factory_service);
  list($module, $plugin_type) = explode('.', $plugin_manager);
  $object = \Drupal\openlayers\Openlayers::load($plugin_type, $item->machine_name);

  // Note: $item->{$schema['export']['export type string']} should have
  // already been set up by export.inc so we can use it safely.
  switch ($form_state['values']['order']) {
    case 'disabled':
      $this->sorts[$name] = empty($item->disabled) . $name;
      break;
    case 'title':
      $this->sorts[$name] = $item->{$this->plugin['export']['admin_title']};
      break;
    case 'name':
      $this->sorts[$name] = $name;
      break;
    case 'class':
      $this->sorts[$name] = $name;
      break;
    case 'storage':
      $this->sorts[$name] = $item->{$schema['export']['export type string']} . $name;
      break;
  }
  switch ($item->type) {
    case t('Default'):
    default:
      $type = t('In code');
      break;
    case t('Normal'):
      $type = t('In database');
      break;
    case t('Overridden'):
      $type = t('Database overriding code');
  }

  // Generate a map and use the style on it to make a preview.

  /** @var MapInterface $map */
  $map = Openlayers::load('map', 'openlayers_ui_map_style_demo');
  $layer = $map
    ->getCollection()
    ->getObjectById('layer', 'openlayers_ui_layer_style_demo');
  $map_render = $map
    ->addLayer($layer
    ->setStyle($object))
    ->render();
  $this->rows[$name]['data'] = array();
  $this->rows[$name]['class'] = !empty($item->disabled) ? array(
    'ctools-export-ui-disabled',
  ) : array(
    'ctools-export-ui-enabled',
  );
  $this->rows[$name]['data'][] = array(
    'data' => $map_render,
    'class' => array(
      'ctools-export-ui-title',
    ),
  );

  // If we have an admin title, make it the first row.
  if (!empty($this->plugin['export']['admin_title'])) {
    $this->rows[$name]['data'][] = array(
      'data' => check_plain($item->{$this->plugin['export']['admin_title']}),
      'class' => array(
        'ctools-export-ui-title',
      ),
    );
  }
  $this->rows[$name]['data'][] = array(
    'data' => check_plain($name),
    'class' => array(
      'ctools-export-ui-name',
    ),
  );
  $this->rows[$name]['data'][] = array(
    'data' => check_plain($item->factory_service),
    'class' => array(
      'ctools-export-ui-service',
    ),
  );
  $this->rows[$name]['data'][] = array(
    'data' => $type,
    'class' => array(
      'ctools-export-ui-storage',
    ),
  );
  $ops = theme('links__ctools_dropbutton', array(
    'links' => $operations,
    'attributes' => array(
      'class' => array(
        'links',
        'inline',
      ),
    ),
  ));
  $this->rows[$name]['data'][] = array(
    'data' => $ops,
    'class' => array(
      'ctools-export-ui-operations',
    ),
  );

  // Add an automatic mouseover of the description if one exists.
  if (!empty($this->plugin['export']['admin_description'])) {
    $this->rows[$name]['title'] = $item->{$this->plugin['export']['admin_description']};
  }
}