DefaultController.php in Shorten URLs 8.2
File
modules/record_shorten/src/Controller/DefaultController.php
View source
<?php
namespace Drupal\record_shorten\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Render\RendererInterface;
class DefaultController extends ControllerBase {
protected $database;
protected $renderer;
public function __construct(Connection $database, RendererInterface $renderer) {
$this->database = $database;
$this->renderer = $renderer;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('database'), $container
->get('renderer'));
}
public function page() {
$build = [];
$total = $this->database
->query("SELECT COUNT(sid) FROM {record_shorten}")
->fetchField();
$build['summary']['#markup'] = '<p>' . $this
->formatPlural($total, '1 shortened URL has been recorded.', '@count shortened URLs have been recorded.');
$build['records_table']['#markup'] = record_shorten_records_table();
$form = $this
->formBuilder()
->getForm('Drupal\\record_shorten\\Form\\RecordshortenClearAll');
$build['clear']['#markup'] = $this->renderer
->render($form);
return $build;
}
}