function CustomServicesAddForm::shorten_cs_services_table in Shorten URLs 8
Displays the table of existing custom services.
1 call to CustomServicesAddForm::shorten_cs_services_table()
- CustomServicesAddForm::buildForm in modules/
shorten_cs/ src/ Form/ CustomServicesAddForm.php - Form constructor.
File
- modules/
shorten_cs/ src/ Form/ CustomServicesAddForm.php, line 124
Class
- CustomServicesAddForm
- Settings form.
Namespace
Drupal\shorten_cs\FormCode
function shorten_cs_services_table() {
$header = array(
t('Name'),
t('URL'),
t('Type'),
t('XML/JSON tag'),
t('Actions'),
);
$rows = array();
$result = db_query("SELECT * FROM {shorten_cs} ORDER BY name ASC")
->fetchAll();
foreach ($result as $service) {
$service = (array) $service;
$service = array(
'sid' => $service['sid'],
'name' => \Drupal\Component\Utility\Html::escape($service['name']),
'url' => \Drupal\Component\Utility\Html::escape($service['url']),
'type' => $service['type'],
'tag' => \Drupal\Component\Utility\Html::escape($service['tag']),
);
$options = [
'absolute' => TRUE,
];
$actions = [
'#markup' => \Drupal\Core\Link::createFromRoute('edit', 'shorten_cs.edit_form', [
'service' => $service['sid'],
], $options)
->toString() . ' ' . \Drupal\Core\Link::createFromRoute('delete', 'shorten_cs.delete_form', [
'service' => $service['sid'],
], $options)
->toString(),
];
$service['actions'] = \Drupal::service('renderer')
->render($actions);
unset($service['sid']);
$rows[] = $service;
}
if (!empty($rows)) {
$table = array(
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array(
'id' => 'shorten_custom_services',
),
);
return drupal_render($table);
}
return '';
}