You are here

function record_shorten_records_table in Shorten URLs 8

Same name and namespace in other branches
  1. 8.2 modules/record_shorten/record_shorten.module \record_shorten_records_table()
  2. 6 record_shorten.module \record_shorten_records_table()
  3. 7.2 record_shorten.module \record_shorten_records_table()
  4. 7 record_shorten.module \record_shorten_records_table()

Builds a list of shortened URLs.

1 call to record_shorten_records_table()
DefaultController::page in modules/record_shorten/src/Controller/DefaultController.php
Page build for Record Shorten

File

modules/record_shorten/record_shorten.module, line 41
Records shortened URLs.

Code

function record_shorten_records_table() {

  // @TODO : Views display plugin needs to be fixed.
  // if (\Drupal::moduleHandler()->moduleExists('views')) {
  //   return views_embed_view('record_shorten', 'default');
  // }
  $header = array(
    t('Original'),
    t('Short'),
    t('Service'),
  );
  $rows = array();

  // SELECT original, short, service FROM {record_shorten} ORDER BY sid DESC
  $result = db_select('record_shorten', 'rs')
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->limit(10)
    ->fields('rs', array(
    'original',
    'short',
    'service',
  ))
    ->orderBy('rs.sid', 'DESC')
    ->execute();
  foreach ($result as $row) {

    // Sigh... DBTNG doesn't have a ->fetchAsNonAssocArray()
    $rows[] = array(
      \Drupal\Component\Utility\Html::escape($row->original),
      \Drupal\Component\Utility\Html::escape($row->short),
      \Drupal\Component\Utility\Html::escape($row->service),
    );
  }
  $table = array(
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );

  // Render Table.
  $output = drupal_render($table);

  // Finally add Pager.
  $pager = array(
    '#type' => 'pager',
  );
  $output .= drupal_render($pager);
  return $output;
}