EmptyPageController.php in Empty Page 8
File
src/Controller/EmptyPageController.php
View source
<?php
namespace Drupal\empty_page\Controller;
use Drupal\Core\Url;
use Drupal\Core\Link;
class EmptyPageController {
public function emptyPageList() {
$header = [
t('INTERNAL PATH'),
[
'data' => t('Operations'),
'colspan' => 2,
],
];
$rows = [];
$callbacks = self::emptyPageGetCallbacks();
if (!empty($callbacks)) {
foreach ($callbacks as $cid => $callback) {
$view_url = Url::fromRoute('empty_page.page_' . $cid);
$edit_url = Url::fromRoute('empty_page.edit_callback', [
'cid' => $cid,
]);
$delete_url = Url::fromRoute('empty_page.delete_callback', [
'cid' => $cid,
]);
$title = $callback['page_title'] ?: t('No title');
$row = [
Link::fromTextAndUrl($title, $view_url),
Link::fromTextAndUrl(t('Edit'), $edit_url),
Link::fromTextAndUrl(t('Delete'), $delete_url),
];
$rows[] = $row;
}
}
$table = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No callbacks exist yet.'),
];
$build = [
'#type' => 'details',
'#title' => 'Manage',
'#children' => $table,
'#open' => TRUE,
];
return $build;
}
public static function emptyPageGetCallbacks() {
$settings = \Drupal::configFactory()
->get('empty_page.settings')
->getRawData();
$results = [];
foreach ($settings as $key => $val) {
if (substr($key, 0, 9) == 'callback_') {
$results[$val['cid']] = $val;
}
}
return $results;
}
}