2024-01-08 23:38:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Drupal\example\Controller;
|
|
|
|
|
|
|
|
use Drupal\Core\Controller\ControllerBase;
|
2024-01-13 22:49:20 +00:00
|
|
|
use Drupal\example\Repository\PostNodeRepository;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
2024-01-08 23:38:01 +00:00
|
|
|
|
|
|
|
class BlogPageController extends ControllerBase {
|
|
|
|
|
2024-01-13 22:49:20 +00:00
|
|
|
public function __construct(
|
|
|
|
private PostNodeRepository $postNodeRepository,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2024-01-08 23:38:01 +00:00
|
|
|
public function __invoke(): array {
|
2024-01-13 22:49:20 +00:00
|
|
|
$nodes = $this->postNodeRepository->findAll();
|
2024-01-08 23:38:01 +00:00
|
|
|
|
|
|
|
$build = [];
|
|
|
|
$build['content']['#theme'] = 'item_list';
|
|
|
|
foreach ($nodes as $node) {
|
|
|
|
$build['content']['#items'][] = $node->label();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $build;
|
|
|
|
}
|
|
|
|
|
2024-01-13 22:49:20 +00:00
|
|
|
public static function create(ContainerInterface $container): self {
|
|
|
|
return new self(
|
|
|
|
$container->get(PostNodeRepository::class),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-01-08 23:38:01 +00:00
|
|
|
}
|