Re-add syntax highlighting to daily emails and
...ATDC lessons
This commit is contained in:
parent
0d9bb37503
commit
5fbf48d9ac
48 changed files with 186 additions and 165 deletions
|
|
@ -26,7 +26,7 @@ This will contain the `PostNodeRepository` class that will be responsible for lo
|
|||
|
||||
Add this as the initial content:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
<?php
|
||||
|
||||
namespace Drupal\atdc\Repository;
|
||||
|
|
@ -62,7 +62,7 @@ $nodes = $nodeStorage->loadMultiple();
|
|||
|
||||
Add them to the `findAll()` method, alter the first line that gets the `EntityTypeManager` (we'll refactor this later) and return the loaded nodes:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
public function findAll(): array {
|
||||
$nodeStorage = \Drupal::entityTypeManager()->getStorage('node');
|
||||
$nodes = $nodeStorage->loadMultiple();
|
||||
|
|
@ -73,7 +73,7 @@ public function findAll(): array {
|
|||
|
||||
Within the `BlogPageController`, create a constructor method and inject the Repository using constructor property promotion:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
public function __construct(
|
||||
private PostNodeRepository $postNodeRepository,
|
||||
) {
|
||||
|
|
@ -82,7 +82,7 @@ public function __construct(
|
|||
|
||||
Add `use Drupal\atdc\Repository\PostNodeRepository;` if needed, and use it to load the post nodes:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
|
||||
public function __invoke(): array {
|
||||
$nodes = $this->postNodeRepository->findAll();
|
||||
|
|
@ -105,7 +105,7 @@ Currently, the test is failing, as the response code is a `500` status because t
|
|||
|
||||
It's expected within the constructor, but you must add a `create` method to inject it.
|
||||
|
||||
```php
|
||||
```language-php
|
||||
public static function create(ContainerInterface $container): self {
|
||||
return new self(
|
||||
$container->get(PostNodeRepository::class),
|
||||
|
|
@ -123,7 +123,7 @@ To do this, create an `atdc.services.yml` file within your module.
|
|||
|
||||
Add `PostNodeRepository` using the fully-qualified class name as the service name:
|
||||
|
||||
```yaml
|
||||
```language-yaml
|
||||
services:
|
||||
Drupal\atdc\Repository\PostNodeRepository:
|
||||
arguments: []
|
||||
|
|
@ -139,7 +139,7 @@ Before moving on, let's refactor the `PostNodeRepository` and inject the `Entity
|
|||
|
||||
The same as the `BlogPageController`, create a constructor method and inject the `EntityTypeManagerInterface`:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
public function __construct(
|
||||
private EntityTypeManagerInterface $entityTypeManager,
|
||||
) {
|
||||
|
|
@ -148,7 +148,7 @@ public function __construct(
|
|||
|
||||
Add the `use Drupal\Core\Entity\EntityTypeManagerInterface;` if needed, and specify it as an argument so it's injected into the constructor:
|
||||
|
||||
```yaml
|
||||
```language-yaml
|
||||
services:
|
||||
Drupal\atdc\Repository\PostNodeRepository:
|
||||
arguments:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue