Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Drupal\hello\Controller;
- use Drupal\Core\Controller\ControllerBase;
- use Drupal\Core\Database\Connection;
- use Drupal\Core\Datetime\DateFormatter;
- use Drupal\node\NodeInterface;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- class HelloNodeHistoryController extends ControllerBase {
- protected $database;
- protected $dateFormatter;
- public function __construct(Connection $database, DateFormatter $dateFormatter) {
- $this->database = $database;
- $this->dateFormatter = $dateFormatter;
- }
- public static function create(ContainerInterface $container) {
- return new static(
- $container->get('database'),
- $container->get('date.formatter')
- );
- }
- public function content(NodeInterface $node) {
- $query = $this->database->select('hello_node_history', 'hnh')
- ->fields('hnh', array('uid', 'update_time'))
- ->condition('nid', $node->id());
- // Tableau des updates.
- $result = $query->execute();
- $rows = array();
- $userStorage = $this->entityTypeManager()->getStorage('user');
- foreach ($result as $record) {
- $rows[] = array(
- $userStorage->load($record->uid)->toLink(),
- $this->dateFormatter->format($record->update_time),
- );
- }
- $table = array(
- '#theme' => 'table',
- '#header' => array($this->t('Author'), $this->t('Update time')),
- '#rows' => $rows,
- );
- // Pagination.
- $pager = array('#type' => 'pager');
- // On renvoie les 2 render arrays.
- return array(
- 'table' => $table,
- 'pager' => $pager
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement