Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Drupal\hello\Controller;
  4.  
  5. use Drupal\Component\Serialization\Json;
  6. use Drupal\Core\Controller\ControllerBase;
  7. use Drupal\Core\Link;
  8. use Drupal\Core\Url;
  9.  
  10. class NodeListController extends ControllerBase {
  11.  
  12. public function content($nodetype = NULL) {
  13. $storage = $this->entityTypeManager()->getStorage('node');
  14. $query = $storage->getQuery();
  15. if ($nodetype) {
  16. $query->condition('type', $nodetype);
  17. }
  18. $nids = $query->pager(10)->execute();
  19. $nodes = $this->entityTypeManager()->getStorage('node')->loadMultiple($nids);
  20. $items = [];
  21. foreach ($nodes as $node) {
  22. $items[] = $node->toLink();
  23. }
  24. $list = [
  25. '#theme' => 'item_list',
  26. '#items' => $items,
  27. ];
  28. $pager = [
  29. '#type' => 'pager'
  30. ];
  31. return [$list, $pager];
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement