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